vfs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func InitDefault(sqliteFS *embed.FS) error

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

func New(sqliteFS *embed.FS) (*sqlx.DB, error)

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.

Jump to

Keyboard shortcuts

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