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 ¶
- type AutoVacuum
- type JournalMode
- type LockingMode
- type Profile
- func (p *Profile) Apply(db *sql.DB) error
- func (p *Profile) Clone() *Profile
- func (p *Profile) String() string
- func (p *Profile) WithAutoVacuum(mode AutoVacuum) *Profile
- func (p *Profile) WithBusyTimeout(ms int) *Profile
- func (p *Profile) WithCacheSize(kibibytes int) *Profile
- func (p *Profile) WithConnMaxLifetime(d time.Duration) *Profile
- func (p *Profile) WithForeignKeys(enabled bool) *Profile
- func (p *Profile) WithJournalMode(mode JournalMode) *Profile
- func (p *Profile) WithLockingMode(mode LockingMode) *Profile
- func (p *Profile) WithMMapSize(bytes int64) *Profile
- func (p *Profile) WithMaxIdleConns(n int) *Profile
- func (p *Profile) WithMaxOpenConns(n int) *Profile
- func (p *Profile) WithPageSize(bytes int) *Profile
- func (p *Profile) WithQueryOnly(enabled bool) *Profile
- func (p *Profile) WithRecursiveTriggers(enabled bool) *Profile
- func (p *Profile) WithSecureDelete(enabled bool) *Profile
- func (p *Profile) WithSynchronous(mode SynchronousMode) *Profile
- func (p *Profile) WithTempStore(store TempStore) *Profile
- type SynchronousMode
- type TempStore
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 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) WithAutoVacuum ¶
func (p *Profile) WithAutoVacuum(mode AutoVacuum) *Profile
WithAutoVacuum sets the auto_vacuum pragma
func (*Profile) WithBusyTimeout ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
WithQueryOnly sets the query_only pragma
func (*Profile) WithRecursiveTriggers ¶
WithRecursiveTriggers sets the recursive_triggers pragma
func (*Profile) WithSecureDelete ¶
WithSecureDelete sets the secure_delete pragma
func (*Profile) WithSynchronous ¶
func (p *Profile) WithSynchronous(mode SynchronousMode) *Profile
WithSynchronous sets the synchronous pragma
func (*Profile) WithTempStore ¶
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" )