sqlite

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package sqlite provides a SQLite3 database utils.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildConnectionString added in v0.9.0

func BuildConnectionString(file string, opts ...OpOption) (string, error)

BuildConnectionString builds a SQLite connection string based on the file path and options. This is exported for testing purposes. ref. https://www.sqlite.org/c3ref/open.html ref. https://www.sqlite.org/uri.html ref. https://github.com/mattn/go-sqlite3?tab=readme-ov-file#connection-string ref. https://github.com/mattn/go-sqlite3?tab=readme-ov-file#faq

func Compact added in v0.4.0

func Compact(ctx context.Context, db *sql.DB) error

Compact compacts the database by running the VACUUM command.

func IsNoSuchTableError added in v0.9.2

func IsNoSuchTableError(err error) bool

IsNoSuchTableError returns true if the error is a SQLite "no such table" error. This is useful for gracefully handling queries against tables that may not exist yet.

func Open

func Open(file string, opts ...OpOption) (*sql.DB, error)

Helper function to open a SQLite3 database.

func OpenTestDB added in v0.3.8

func OpenTestDB(t *testing.T) (*sql.DB, *sql.DB, func())

func ReadDBSize added in v0.4.0

func ReadDBSize(ctx context.Context, dbRO *sql.DB) (uint64, error)

ReadDBSize reads the size of the database in bytes. It fails if the database file does not exist.

func RunCompact added in v0.5.0

func RunCompact(ctx context.Context, dbFile string) error

RunCompact compacts the database by running the VACUUM command, and prints the size before and after the compact.

func TableExists added in v0.5.0

func TableExists(ctx context.Context, db *sql.DB, name string) (bool, error)

Types

type Op added in v0.3.8

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

type OpOption added in v0.3.8

type OpOption func(*Op)

func WithCache added in v0.9.0

func WithCache(mode string) OpOption

WithCache sets the SQLite cache mode for in-memory databases. Use "shared" to allow multiple connections to share the same in-memory database. If empty (default), no cache parameter is added to the connection string. ref. https://github.com/mattn/go-sqlite3?tab=readme-ov-file#faq

Jump to

Keyboard shortcuts

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