sqlite

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sqlite provides SQLite helpers for testing without containers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InMemory

func InMemory() (*sql.DB, func(), error)

InMemory creates an in-memory SQLite database. This is the fastest option, useful for unit tests.

Example:

db, cleanup, err := sqlite.InMemory()
if err != nil {
    panic(err)
}
defer cleanup()

func NewWithOptions

func NewWithOptions(opts ...Option) (*sql.DB, func(), error)

NewWithOptions starts a SQLite database with custom configuration.

Example:

db, cleanup, err := sqlite.NewWithOptions(
    sqlite.WithMode("memory"),
    sqlite.WithCache("shared"),
)
if err != nil {
    panic(err)
}
defer cleanup()

func TempDB

func TempDB() (*sql.DB, func(), error)

TempDB creates a temporary SQLite database file. The file is automatically removed when the database is closed. Useful when you need persistence but automatic cleanup.

Example:

db, cleanup, err := sqlite.TempDB()
if err != nil {
    panic(err)
}
defer cleanup()

Types

type Option

type Option func(*config.SQLiteConfig)

Option is a functional option for SQLite configuration.

func WithCache

func WithCache(cache string) Option

WithCache sets the cache mode: "shared", "private", or "write".

func WithMode

func WithMode(mode string) Option

WithMode sets the database mode: "memory", "temp", or "file".

func WithPath

func WithPath(path string) Option

WithPath sets the file path for persistent SQLite databases.

Jump to

Keyboard shortcuts

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