vfs

package
v1.60.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: BSD-3-Clause Imports: 13 Imported by: 1

Documentation

Overview

Package vfs exposes a Go fs.FS to SQLite as a read-only VFS.

New registers the file system with SQLite and returns the name it was registered under. Passing that name as the vfs DSN query parameter opens a database read from the wrapped file system instead of from the host one. Paths are resolved by the wrapped fs.FS, so the database is named relative to its root:

name, fsvfs, err := vfs.New(os.DirFS(dir))
if err != nil {
	return err
}

defer fsvfs.Close()

db, err := sql.Open("sqlite", "file:test.db?vfs="+name)

Any fs.FS will do, an embed.FS included, which is what makes this useful for shipping a database inside the binary. The VFS is read only: it has no write path and refuses to create a journal, so a database opened through it can only be read from.

Registration is process-global, as SQLite's own VFS registry is. Each New registers a separate VFS under a fresh name, and FS.Close unregisters it again. Close every database opened through an FS before closing it: while any is open, FS.Close refuses with an error wrapping ErrInUse.

Index

Constants

View Source
const (
	SIGEV_SIGNAL = 0
	SIGEV_NONE   = 1
	SIGEV_THREAD = 2

	SIGEV_THREAD_ID = 4
)
View Source
const (
	SEGV_MAPERR  = 1
	SEGV_ACCERR  = 2
	SEGV_BNDERR  = 3
	SEGV_PKUERR  = 4
	SEGV_ACCADI  = 5
	SEGV_ADIDERR = 6
	SEGV_ADIPERR = 7
)
View Source
const (
	BUS_ADRALN    = 1
	BUS_ADRERR    = 2
	BUS_OBJERR    = 3
	BUS_MCEERR_AR = 4
	BUS_MCEERR_AO = 5
)
View Source
const (
	CLD_EXITED    = 1
	CLD_KILLED    = 2
	CLD_DUMPED    = 3
	CLD_TRAPPED   = 4
	CLD_STOPPED   = 5
	CLD_CONTINUED = 6
)
View Source
const (
	POLL_IN  = 1
	POLL_OUT = 2
	POLL_MSG = 3
	POLL_ERR = 4
	POLL_PRI = 5
	POLL_HUP = 6
)
View Source
const (
	SI_ASYNCNL  = -60
	SI_DETHREAD = -7

	SI_TKILL   = -6
	SI_SIGIO   = -5
	SI_ASYNCIO = -4
	SI_MESGQ   = -3
	SI_TIMER   = -2
	SI_QUEUE   = -1
	SI_USER    = 0
	SI_KERNEL  = 128
)
View Source
const (
	ILL_ILLOPC   = 1
	ILL_ILLOPN   = 2
	ILL_ILLADR   = 3
	ILL_ILLTRP   = 4
	ILL_PRVOPC   = 5
	ILL_PRVREG   = 6
	ILL_COPROC   = 7
	ILL_BADSTK   = 8
	ILL_BADIADDR = 9
)
View Source
const (
	FPE_INTDIV   = 1
	FPE_INTOVF   = 2
	FPE_FLTDIV   = 3
	FPE_FLTOVF   = 4
	FPE_FLTUND   = 5
	FPE_FLTRES   = 6
	FPE_FLTINV   = 7
	FPE_FLTSUB   = 8
	FPE_FLTUNK   = 14
	FPE_CONDTRAP = 15
)
View Source
const (
	SS_ONSTACK = 1
	SS_DISABLE = 2
)

Variables

View Source
var ErrInUse = errors.New("vfs: file system is in use")

ErrInUse is returned, wrapped, by FS.Close while a database opened through the file system is still open.

Functions

func Xsqlite3_fsFS

func Xsqlite3_fsFS(tls *libc.TLS, zName uintptr, pAppData uintptr) uintptr

Types

type FS

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

FS represents a SQLite read only file system backed by Go's fs.FS.

func New

func New(fs fs.FS) (name string, _ *FS, _ error)

New creates a new sqlite VFS and registers it. If successful, the file system can be used with the URI parameter `?vfs=<returned name>`.

func (*FS) Close

func (f *FS) Close() error

Close unregisters f and releases its resources.

Every database opened through f must be closed first. SQLite keeps a pointer to the VFS in each connection and calls through it for as long as the connection is open, so while any file is open through f, Close does nothing and returns an error wrapping ErrInUse; close the databases and call it again. Close must also not run concurrently with opening a database through f: SQLite looks the VFS up before it opens the file, and nothing can tell Close about an open that is between the two.

type Fts5ExtensionApi

type Fts5ExtensionApi = Fts5ExtensionApi1

type Fts5ExtensionApi1

type Fts5ExtensionApi1 = struct {
	// contains filtered or unexported fields
}

type Fts5PhraseIter

type Fts5PhraseIter = Fts5PhraseIter1

type Fts5PhraseIter1

type Fts5PhraseIter1 = struct {
	// contains filtered or unexported fields
}

type VFSFile

type VFSFile = VFSFile1

type VFSFile1

type VFSFile1 = struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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