Documentation
¶
Overview ¶
Package sqlitewriter provides a resilient single-writer queue for SQLite stores.
Index ¶
- Constants
- func ExecSQL(ctx context.Context, sqldb *sql.DB, stmt string) error
- func HasLibsqlDriver() bool
- func HasTursoDriver() bool
- func NormalizeDSN(dsn string) string
- func NormalizeLibsqlDSN(dsn string) string
- func OpenLibsqlHandles(ctx context.Context, dsn string, log zerolog.Logger) (*sql.DB, *bun.DB, error)
- func OpenTursoHandles(ctx context.Context, dsn string, log zerolog.Logger) (*sql.DB, *bun.DB, error)
- func ResolveMainFilePath(rawDSN string) (string, error)
- func TursoDSN(path string) string
- type HandlesOpener
- type Options
- type Queue
Constants ¶
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 ¶
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 ¶
NormalizeDSN returns a file: DSN with shared cache for a local libSQL database.
func NormalizeLibsqlDSN ¶
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 ¶
ResolveMainFilePath resolves the on-disk database file path from a file: DSN or bare path.
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 ¶
New attaches a writer queue to an already-opened database. Call Close when shutting down.