sqlitex

package module
v0.0.0-...-49c0d8c Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 11 Imported by: 0

README

SQLiteX

Go Report Card

Getting Started

go get github.com/gulitsky/sqlitex

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Maintain

func Maintain(ctx context.Context, db *sql.DB, options ...MaintenanceOption) error

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 Open

func Open(driverName string, dataSourceName string, preemptive ...string) (*sql.DB, error)

func OpenMemory

func OpenMemory(driverName string, options ...Option) (*sql.DB, error)

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

func OpenReadOnly(driverName string, filePath string, options ...Option) (*sql.DB, error)

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

func OpenReadWrite(driverName string, filePath string, options ...Option) (*sql.DB, error)

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

func WithBusyTimeout(timeout time.Duration) Option

WithBusyTimeout sets the busy_timeout pragma.

func WithCacheSizeKiB

func WithCacheSizeKiB(size uint64) Option

WithCacheSizeKiB sets the cache_size pragma (in KiB).

func WithMemoryMapSize

func WithMemoryMapSize(size uint64) Option

WithMemoryMapSize sets the mmap_size pragma.

func WithPragma

func WithPragma(name, value string) Option

WithPragma adds or overrides a specific SQLite pragma.

func WithWALAutoCheckpoint

func WithWALAutoCheckpoint(pages uint64) Option

WithWALAutoCheckpoint sets the wal_autocheckpoint pragma (number of pages).

Jump to

Keyboard shortcuts

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