profile

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package profiles provides pre-configured database profiles for different workload types. Each profile optimises SQLite settings for specific use cases like read-heavy operations, write-intensive workloads, or mixed scenarios.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoVacuum

type AutoVacuum string

AutoVacuum defines available auto_vacuum modes

const (
	AutoVacuumNone        AutoVacuum = "NONE"
	AutoVacuumFull        AutoVacuum = "FULL"
	AutoVacuumIncremental AutoVacuum = "INCREMENTAL"
)

type JournalMode

type JournalMode string

JournalMode defines available journal modes for SQLite

const (
	JournalDelete   JournalMode = "DELETE"
	JournalTruncate JournalMode = "TRUNCATE"
	JournalPersist  JournalMode = "PERSIST"
	JournalMemory   JournalMode = "MEMORY"
	JournalWal      JournalMode = "WAL"
	JournalOff      JournalMode = "OFF"
)

type LockingMode

type LockingMode string

LockingMode defines available locking modes

const (
	LockingNormal    LockingMode = "NORMAL"
	LockingExclusive LockingMode = "EXCLUSIVE"
)

type Profile

type Profile struct {
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
	Pragmas         map[string]interface{}
}

Profile holds configuration for database connections

func New

func New() *Profile

New creates a new empty profile with initialized pragmas map

func ReadBalanced

func ReadBalanced() *Profile

ReadBalanced provides good read performance suitable for most applications

func ReadHeavy

func ReadHeavy() *Profile

ReadHeavy maximises read throughput for high-concurrency scenarios

func ReadLight

func ReadLight() *Profile

ReadLight provides basic read performance with low resource usage

func WriteBalanced

func WriteBalanced() *Profile

WriteBalanced provides good write performance suitable for most applications

func WriteHeavy

func WriteHeavy() *Profile

WriteHeavy maximises write throughput for high-volume write scenarios

func WriteLight

func WriteLight() *Profile

WriteLight provides basic write performance with low resource usage

func (*Profile) Apply

func (p *Profile) Apply(db *sql.DB) error

Apply configures a database connection with this profile

func (*Profile) Clone

func (p *Profile) Clone() *Profile

Clone returns a deep copy of the profile

func (*Profile) String

func (p *Profile) String() string

String returns a string representation of the profile

func (*Profile) WithAutoVacuum

func (p *Profile) WithAutoVacuum(mode AutoVacuum) *Profile

WithAutoVacuum sets the auto_vacuum pragma

func (*Profile) WithBusyTimeout

func (p *Profile) WithBusyTimeout(ms int) *Profile

WithBusyTimeout sets the busy_timeout pragma for database lock retries. Specifies how long (in milliseconds) to wait for locks before returning SQLITE_BUSY. Higher values reduce lock contention errors but may increase latency. Common values: 5000 (5 seconds, default), 10000 (high contention), 1000 (low latency)

func (*Profile) WithCacheSize

func (p *Profile) WithCacheSize(kibibytes int) *Profile

WithCacheSize sets the cache_size pragma for SQLite's page cache. Positive values specify cache size in KiB, negative values specify number of pages. Larger cache improves read performance but uses more memory. Example: -102400 = 100MB cache (recommended for most applications)

func (*Profile) WithConnMaxLifetime

func (p *Profile) WithConnMaxLifetime(d time.Duration) *Profile

WithConnMaxLifetime sets the maximum amount of time a connection may be reused. Prevents accumulation of connection-specific state and handles server restarts. Common values: time.Hour (default), time.Minute*30 (high churn), 0 (unlimited)

func (*Profile) WithForeignKeys

func (p *Profile) WithForeignKeys(enabled bool) *Profile

WithForeignKeys sets the foreign_keys pragma

func (*Profile) WithJournalMode

func (p *Profile) WithJournalMode(mode JournalMode) *Profile

WithJournalMode sets the journal_mode pragma

func (*Profile) WithLockingMode

func (p *Profile) WithLockingMode(mode LockingMode) *Profile

WithLockingMode sets the locking_mode pragma

func (*Profile) WithMMapSize

func (p *Profile) WithMMapSize(bytes int64) *Profile

WithMMapSize sets the mmap_size pragma for memory-mapped I/O. Specifies the maximum size in bytes that SQLite will use for memory-mapped files. Larger values can improve performance for read-heavy workloads. Common values: 268435456 (256MB), 536870912 (512MB), 0 (disable mmap)

func (*Profile) WithMaxIdleConns

func (p *Profile) WithMaxIdleConns(n int) *Profile

WithMaxIdleConns sets the maximum number of idle connections in the pool. Should be less than or equal to MaxOpenConns. Higher values reduce connection overhead but use more resources. Typical values: 2-12 depending on workload.

func (*Profile) WithMaxOpenConns

func (p *Profile) WithMaxOpenConns(n int) *Profile

WithMaxOpenConns sets the maximum number of open connections to the database. For read profiles: higher values allow more concurrent queries (5-25 typical). For write profiles: should be 1 due to SQLite's single-writer constraint.

func (*Profile) WithPageSize

func (p *Profile) WithPageSize(bytes int) *Profile

WithPageSize sets the page_size pragma for database pages. Must be a power of 2 between 512 and 65536 bytes. Larger pages reduce overhead for large records but use more memory. Common values: 4096 (default), 8192 (good for write-heavy), 16384 (large records)

func (*Profile) WithQueryOnly

func (p *Profile) WithQueryOnly(enabled bool) *Profile

WithQueryOnly sets the query_only pragma

func (*Profile) WithRecursiveTriggers

func (p *Profile) WithRecursiveTriggers(enabled bool) *Profile

WithRecursiveTriggers sets the recursive_triggers pragma

func (*Profile) WithSecureDelete

func (p *Profile) WithSecureDelete(enabled bool) *Profile

WithSecureDelete sets the secure_delete pragma

func (*Profile) WithSynchronous

func (p *Profile) WithSynchronous(mode SynchronousMode) *Profile

WithSynchronous sets the synchronous pragma

func (*Profile) WithTempStore

func (p *Profile) WithTempStore(store TempStore) *Profile

WithTempStore sets the temp_store pragma

type SynchronousMode

type SynchronousMode string

SynchronousMode defines available synchronous levels for SQLite

const (
	SyncOff    SynchronousMode = "0"
	SyncNormal SynchronousMode = "1"
	SyncFull   SynchronousMode = "2"
	SyncExtra  SynchronousMode = "3"
)

type TempStore

type TempStore string

TempStore defines available temp_store modes

const (
	TempStoreDefault TempStore = "DEFAULT"
	TempStoreFile    TempStore = "FILE"
	TempStoreMemory  TempStore = "MEMORY"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL