Documentation
¶
Overview ¶
Package database provides SQLite connection management with optimized pragmas.
Index ¶
- type DatabaseConfig
- type Manager
- func (m *Manager) ApplyPragmas(ctx context.Context) error
- func (m *Manager) BeginTx(ctx context.Context) (*sql.Tx, error)
- func (m *Manager) Close() error
- func (m *Manager) DB() *sql.DB
- func (m *Manager) IsInMemory() bool
- func (m *Manager) Path() string
- func (m *Manager) Ping(ctx context.Context) error
- func (m *Manager) Stats() sql.DBStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DatabaseConfig ¶
type DatabaseConfig struct {
// Path is the filesystem path to the SQLite database file.
// Use ":memory:" for an in-memory database (useful for testing).
Path string
// MaxOpenConns sets the maximum number of open connections.
// Default: 25
MaxOpenConns int
// MaxIdleConns sets the maximum number of idle connections.
// Default: 10
MaxIdleConns int
// ConnMaxLifetime sets the maximum lifetime of a connection.
// Default: 30 minutes
ConnMaxLifetime time.Duration
// EnableWAL enables Write-Ahead Logging mode.
// Default: true
EnableWAL bool
// CacheSize sets the SQLite cache size in kilobytes.
// Negative values set the cache size in pages.
// Default: -64000 (64MB)
CacheSize int
// MMapSize sets the memory-mapped I/O size in bytes.
// Default: 268435456 (256MB)
MMapSize int64
// BusyTimeout sets the timeout for busy waiting in milliseconds.
// Default: 5000 (5 seconds)
BusyTimeout int
}
DatabaseConfig holds configuration for database connection.
func DefaultConfig ¶
func DefaultConfig() DatabaseConfig
DefaultConfig returns a DatabaseConfig with sensible defaults.
func InMemoryConfig ¶
func InMemoryConfig() DatabaseConfig
InMemoryConfig returns a DatabaseConfig for an in-memory database.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages SQLite database connections with optimized settings.
func NewManager ¶
func NewManager(cfg DatabaseConfig) (*Manager, error)
NewManager creates a new database manager with the given configuration.
func (*Manager) ApplyPragmas ¶
ApplyPragmas applies SQLite pragma settings for optimal performance. These pragmas are applied on each connection in the pool.
func (*Manager) BeginTx ¶
BeginTx starts a new transaction with the given context. The transaction must be committed or rolled back by the caller.
func (*Manager) DB ¶
DB returns the underlying database connection. The returned *sql.DB is safe for concurrent use by multiple goroutines.
func (*Manager) IsInMemory ¶
IsInMemory returns true if the database is in-memory.