vfs

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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 dbgorm/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 dbgorm 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; dbgorm.Default() returns the shared *gorm.DB. Subsequent calls are silently ignored (sync.Once).

// InitDefault is a no-op here because TestSingleton_Lifecycle ran first.
_ = sqlitevfs.InitDefault(&testFS)
fmt.Println(dbgorm.Default() != nil)

func New

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

New opens a GORM 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 GORM 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