sqlitewriter

package
v0.0.1-rc Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package sqlitewriter provides a resilient single-writer queue for SQLite stores.

Index

Constants

View Source
const (
	DefaultQueueCapacity = 1024
	// DefaultTaskTimeout bounds one writer task; callers blocked on RunWrite are released on timeout.
	DefaultTaskTimeout = 2 * time.Minute
)

Variables

This section is empty.

Functions

func ExecSQL

func ExecSQL(ctx context.Context, sqldb *sql.DB, stmt string) error

ExecSQL executes stmt, retrying as QueryRow when libsql reports that the statement returned rows.

func HasLibsqlDriver

func HasLibsqlDriver() bool

HasLibsqlDriver reports whether the go-libsql driver is linked (CGO build).

func HasTursoDriver

func HasTursoDriver() bool

HasTursoDriver reports whether the tursogo database/sql driver is linked.

func NormalizeDSN

func NormalizeDSN(dsn string) string

NormalizeDSN returns a file: DSN with shared cache for a local libSQL database.

func NormalizeLibsqlDSN

func NormalizeLibsqlDSN(dsn string) string

NormalizeLibsqlDSN returns a file: DSN for go-libsql local databases.

func OpenLibsqlHandles

func OpenLibsqlHandles(ctx context.Context, dsn string, log zerolog.Logger) (*sql.DB, *bun.DB, error)

OpenLibsqlHandles opens a local libSQL file, applies WAL pragmas, and returns sql.DB + bun.DB.

func OpenTursoHandles

func OpenTursoHandles(ctx context.Context, dsn string, log zerolog.Logger) (*sql.DB, *bun.DB, error)

OpenTursoHandles opens a local database with tursogo, WAL, and a read pool.

func ResolveMainFilePath

func ResolveMainFilePath(rawDSN string) (string, error)

ResolveMainFilePath resolves the on-disk database file path from a file: DSN or bare path.

func TursoDSN

func TursoDSN(path string) string

TursoDSN returns a tursogo DSN for a filesystem path. index_method enables the Turso full-text index used by NIP-50 search.

Types

type HandlesOpener

type HandlesOpener func(ctx context.Context, dsn string, log zerolog.Logger) (*sql.DB, *bun.DB, error)

HandlesOpener opens a database and returns sql.DB + bun.DB handles.

type Options

type Options struct {
	Engine        string // e.g. "turso", "sqlitemeta"
	Log           zerolog.Logger
	DSN           string
	OpenHandles   HandlesOpener
	QueueCapacity int
	TaskTimeout   time.Duration
}

Options configures a writer queue.

type Queue

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

Queue serializes mutating SQLite/libSQL work on one goroutine with panic recovery, hard timeouts (callers unblock; reconnect waits until the native call returns), optional reconnect on I/O errors, and debug tracing.

func New

func New(sqldb *sql.DB, db *bun.DB, opts Options) *Queue

New attaches a writer queue to an already-opened database. Call Close when shutting down.

func (*Queue) Close

func (q *Queue) Close() error

Close stops the supervisor and closes the underlying sql.DB.

func (*Queue) DB

func (q *Queue) DB() *bun.DB

DB returns the Bun handle used for concurrent reads. Safe under reconnect.

func (*Queue) RunWrite

func (q *Queue) RunWrite(ctx context.Context, label string, run func(ctx context.Context, db bun.IDB) error) error

RunWrite enqueues one mutating task and blocks until it completes, times out, or the store closes.

Jump to

Keyboard shortcuts

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