Documentation
¶
Overview ¶
Package vfs opens a SQLite database embedded inside a Go binary using modernc.org/sqlite/vfs and Go's embed.FS.
The embedded database file must reside at config/sqlite.db inside the provided embed.FS. This package is intended for read-heavy, binary-embedded datasets such as reference tables or look-up data shipped with the binary.
Import this sub-package only when distributing a SQLite database as part of the binary. For regular file-based databases use dbsqlx/sqlite instead.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitDefault ¶
InitDefault opens the embedded SQLite VFS database and stores it as the process-wide dbsqlx default. Only the first call has any effect; subsequent calls are a no-op (sync.Once).
Example ¶
ExampleInitDefault shows the singleton pattern for an embedded SQLite VFS database. Call InitDefault once at application startup; dbsqlx.Default() returns the shared *sqlx.DB. Subsequent calls are silently ignored (sync.Once).
// InitDefault is a no-op here because TestSingleton_Lifecycle ran first. _ = sqlitevfs.InitDefault(&testFS) fmt.Println(dbsqlx.Default() != nil)
func New ¶
New opens a sqlx database backed by a SQLite database embedded inside sqliteFS. The embedded file must be located at config/sqlite.db within the FS.
Example ¶
ExampleNew shows how to open a sqlx database backed by an embedded SQLite file. The embedded FS must contain config/sqlite.db.
//go:embed config var sqliteFS embed.FS
testFS is declared in vfs_test.go and shared across the test package.
db, err := sqlitevfs.New(&testFS) fmt.Println(err == nil) fmt.Println(db != nil)
Output: true true
Types ¶
This section is empty.