Documentation
¶
Index ¶
- func Maintain(ctx context.Context, db *sql.DB, options ...MaintenanceOption) error
- func Open(driverName string, dataSourceName string, preemptive ...string) (*sql.DB, error)
- func OpenMemory(driverName string, options ...Option) (*sql.DB, error)
- func OpenReadOnly(driverName string, filePath string, options ...Option) (*sql.DB, error)
- func OpenReadWrite(driverName string, filePath string, options ...Option) (*sql.DB, error)
- type MaintenanceOption
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Maintain ¶
Maintain starts a background maintenance loop for the database. It performs periodic WAL checkpoints and optimizations. It returns only when ctx is canceled or a fatal error occurs during final checkpoint.
func OpenMemory ¶
OpenMemory opens a new shared memory database. Each call creates a distinct database unless a specific name is provided via custom options (not yet supported).
func OpenReadOnly ¶
OpenReadOnly opens a database in read-only mode. It sets "query_only=yes" and optimizes cache for reading.
The connection pool is sized based on GOMAXPROCS.
func OpenReadWrite ¶
OpenReadWrite opens a database in read-write mode. It sets "mode=rwc", "txlock=immediate", and strictly limits concurrency to 1 connection to avoid SQLITE_BUSY errors during transaction upgrades.
Types ¶
type MaintenanceOption ¶
type MaintenanceOption func(*maintenanceConfig) error
MaintenanceOption configures the maintenance loop.
func WithCheckpointPeriod ¶
func WithCheckpointPeriod(period time.Duration) MaintenanceOption
WithCheckpointPeriod sets the interval for PRAGMA wal_checkpoint(PASSIVE).
func WithLogger ¶
func WithLogger(logger *slog.Logger) MaintenanceOption
WithLogger sets the structured logger for maintenance events.
func WithOptimizePeriod ¶
func WithOptimizePeriod(period time.Duration) MaintenanceOption
WithOptimizePeriod sets the interval for PRAGMA optimize.
type Option ¶
type Option func(*config) error
Option configures the database connection.
func WithBusyTimeout ¶
WithBusyTimeout sets the busy_timeout pragma.
func WithCacheSizeKiB ¶
WithCacheSizeKiB sets the cache_size pragma (in KiB).
func WithMemoryMapSize ¶
WithMemoryMapSize sets the mmap_size pragma.
func WithPragma ¶
WithPragma adds or overrides a specific SQLite pragma.
func WithWALAutoCheckpoint ¶
WithWALAutoCheckpoint sets the wal_autocheckpoint pragma (number of pages).