Documentation
¶
Overview ¶
Package sqlite provides a SQLite3 database utils.
Index ¶
- func BuildConnectionString(file string, opts ...OpOption) (string, error)
- func Compact(ctx context.Context, db *sql.DB) error
- func Open(file string, opts ...OpOption) (*sql.DB, error)
- func OpenTestDB(t *testing.T) (*sql.DB, *sql.DB, func())
- func ReadDBSize(ctx context.Context, dbRO *sql.DB) (uint64, error)
- func RunCompact(ctx context.Context, dbFile string) error
- func TableExists(ctx context.Context, db *sql.DB, name string) (bool, error)
- type Op
- type OpOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildConnectionString ¶ added in v0.9.0
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 ReadDBSize ¶ added in v0.4.0
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
RunCompact compacts the database by running the VACUUM command, and prints the size before and after the compact.
Types ¶
type OpOption ¶ added in v0.3.8
type OpOption func(*Op)
func WithCache ¶ added in v0.9.0
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
func WithReadOnly ¶ added in v0.3.8
ref. https://github.com/mattn/go-sqlite3/issues/1179#issuecomment-1638083995