sqlite

package
v0.1.37 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package sqlite opens a file-backed SQLite database with a serialized writer, a query-only read pool, and optional buffered asynchronous writes.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed is returned when a write is submitted after Close starts.
	ErrClosed = errors.New("sqlite database is closed")
	// ErrWriteQueueFull is returned when the asynchronous write queue is full.
	ErrWriteQueueFull = errors.New("sqlite asynchronous write queue is full")
	// ErrWriteErrorHandlerRequired is returned when an asynchronous write has no error handler.
	ErrWriteErrorHandlerRequired = errors.New("sqlite asynchronous writes require OnWriteError")
)

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB owns separate SQLite read and write pools over one file.

func Open

func Open(options Options) (*DB, error)

Open opens or creates options.Path and starts its asynchronous writer.

func (*DB) Close

func (d *DB) Close() error

Close drains accepted asynchronous writes and closes both pools.

func (*DB) ExecAsync

func (d *DB) ExecAsync(statement string, args ...any) error

ExecAsync queues a parameterized SQL statement for asynchronous execution.

func (*DB) InsertAsync

func (d *DB) InsertAsync(table string, values map[string]any) error

InsertAsync queues one map-shaped row for insertion into table.

func (*DB) InsertTableAsync

func (d *DB) InsertTableAsync(table sqlitetable.Table, rows []query.Row) error

InsertTableAsync queues typed rows for insertion through sqlitetable.Table.

func (*DB) Lease

func (d *DB) Lease() func()

Lease prevents mutations until the returned release function is called.

func (*DB) Path

func (d *DB) Path() string

Path returns the absolute database file path.

func (*DB) ReadDSN

func (d *DB) ReadDSN() string

ReadDSN returns a query-only SQLite DSN for the database file.

func (*DB) Reader

func (d *DB) Reader() *sql.DB

Reader returns the query-only read pool. Callers that require several statements to observe one stable mutation boundary must hold Lease as well.

func (*DB) Write

func (d *DB) Write(mutation Mutation) error

Write waits for exclusive access and runs mutation immediately.

func (*DB) WriteAsync

func (d *DB) WriteAsync(mutation Mutation) error

WriteAsync queues mutation for an asynchronous batch buffered for 100 milliseconds. It returns ErrWriteQueueFull rather than blocking.

type Mutation

type Mutation func(*sql.DB) error

Mutation changes a SQLite database through its serialized writer.

type Options

type Options struct {
	// Path is the SQLite database file.
	Path string

	// OnWriteError receives failures from accepted asynchronous mutations.
	// It is called after the write lock is released.
	OnWriteError func(error)
}

Options configure a file-backed SQLite database.

Jump to

Keyboard shortcuts

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