package
0.18.0
Repository: https://github.com/ncruces/go-sqlite3.git
Documentation: pkg.go.dev

# README

Go SQLite VFS API

This package implements the SQLite OS Interface (aka VFS).

It replaces the default SQLite VFS with a pure Go implementation, and exposes interfaces that should allow you to implement your own custom VFSes.

Since it is a from scratch reimplementation, there are naturally some ways it deviates from the original.

The main differences are file locking and WAL mode support.

File Locking

POSIX advisory locks, which SQLite uses on Unix, are broken by design.

On Linux and macOS, this module uses OFD locks to synchronize access to database files. OFD locks are fully compatible with POSIX advisory locks.

This module can also use BSD locks, albeit with reduced concurrency (BEGIN IMMEDIATE behaves like BEGIN EXCLUSIVE). On BSD, macOS, and illumos, BSD locks are fully compatible with POSIX advisory locks; on Linux and z/OS, they are fully functional, but incompatible; elsewhere, they are very likely broken. BSD locks are the default on BSD and illumos, but you can opt into them with the sqlite3_flock build tag.

On Windows, this module uses LockFileEx and UnlockFileEx, like SQLite.

Otherwise, file locking is not supported, and you must use nolock=1 (or immutable=1) to open database files. To use the database/sql driver with nolock=1 you must disable connection pooling by calling db.SetMaxOpenConns(1).

You can use vfs.SupportsFileLocking to check if your build supports file locking.

Write-Ahead Logging

On 64-bit Unix, this module uses mmap to implement shared-memory for the WAL-index, like SQLite.

To allow mmap to work, each connection needs to reserve up to 4GB of address space. To limit the address space each connection reserves, use WithMemoryLimitPages.

With BSD locks a WAL database can only be accessed by a single proccess. Other processes that attempt to access a database locked with BSD locks, will fail with the SQLITE_PROTOCOL error code.

Otherwise, WAL support is limited, and EXCLUSIVE locking mode must be set to create, read, and write WAL databases. To use EXCLUSIVE locking mode with the database/sql driver you must disable connection pooling by calling db.SetMaxOpenConns(1).

You can use vfs.SupportsSharedMemory to check if your build supports shared memory.

Batch-Atomic Write

On 64-bit Linux, this module supports batch-atomic writes on the F2FS filesystem.

Build Tags

The VFS can be customized with a few build tags:

  • sqlite3_flock forces the use of BSD locks; it can be used on z/OS to enable locking, and elsewhere to test BSD locks.
  • sqlite3_nosys prevents importing x/sys; disables locking and shared memory on all platforms.
  • sqlite3_noshm disables shared memory on all platforms.

[!IMPORTANT] The default configuration of this package is compatible with the standard Unix and Windows SQLite VFSes; sqlite3_flock builds are compatible with the unix-flock VFS. If incompatible file locking is used, accessing databases concurrently with other SQLite libraries will eventually corrupt data.

# Packages

Package adiantum wraps an SQLite VFS to offer encryption at rest.
Package memdb implements the "memdb" SQLite VFS.
Package readervfs implements an SQLite VFS for immutable databases.
No description provided by the author

# Functions

ExportHostFunctions is an internal API users need not call directly.
Find returns a VFS given its name.
GetFilename is an internal API users should not call directly.
NewSharedMemory returns a shared-memory WAL-index backed by a file with the given path.
Register registers a VFS.
Unregister unregisters a VFS.

# Constants

No description provided by the author
Unused */.
Used by PRAGMA temp_store_directory */.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
xLock() only */.
xUnlock() only */.
internal use only */.
xLock() only */.
xLock() or xUnlock() */.
VFS only */.
Ok for sqlite3_open_v2() */.
VFS only */.
VFS only */.
Ok for sqlite3_open_v2() */.
VFS only */.
VFS only */.
Ok for sqlite3_open_v2() */.
Ok for sqlite3_open_v2() */.
Ok for sqlite3_open_v2() */.
Ok for sqlite3_open_v2() */.
Ok for sqlite3_open_v2() */.
Ok for sqlite3_open_v2() */.
Ok for sqlite3_open_v2() */.
VFS only */.
VFS only */.
VFS only */.
VFS only */.
VFS only */.
Ok for sqlite3_open_v2() */.
VFS only */.
SupportsFileLocking is false on platforms that do not support file locking.
SupportsSharedMemory is false on platforms that do not support shared memory.
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Filename is used by SQLite to pass filenames to the Open method of a VFS.

# Interfaces

A File represents an open file in the OS interface layer.
FileBatchAtomicWrite extends File to implement the SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE and SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE file control opcodes.
FileCheckpoint extends File to implement the SQLITE_FCNTL_CKPT_START and SQLITE_FCNTL_CKPT_DONE file control opcodes.
FileChunkSize extends File to implement the SQLITE_FCNTL_CHUNK_SIZE file control opcode.
FileCommitPhaseTwo extends File to implement the SQLITE_FCNTL_COMMIT_PHASETWO file control opcode.
FileHasMoved extends File to implement the SQLITE_FCNTL_HAS_MOVED file control opcode.
FileLockState extends File to implement the SQLITE_FCNTL_LOCKSTATE file control opcode.
FileOverwrite extends File to implement the SQLITE_FCNTL_OVERWRITE file control opcode.
FilePersistentWAL extends File to implement the SQLITE_FCNTL_PERSIST_WAL file control opcode.
FilePowersafeOverwrite extends File to implement the SQLITE_FCNTL_POWERSAFE_OVERWRITE file control opcode.
FilePragma extends File to implement the SQLITE_FCNTL_PRAGMA file control opcode.
FileSharedMemory extends File to possibly implement shared-memory for the WAL-index.
FileSizeHint extends File to implement the SQLITE_FCNTL_SIZE_HINT file control opcode.
SharedMemory is a shared-memory WAL-index implementation.
A VFS defines the interface between the SQLite core and the underlying operating system.
VFSFilename extends VFS with the ability to use Filename objects for opening files.

# Type aliases

AccessFlag is a flag for the [VFS] Access method.
DeviceCharacteristic is a flag retuned by the [File] DeviceCharacteristics method.
LockLevel is a value used with [File] Lock and Unlock methods.
OpenFlag is a flag for the [VFS] Open method.
SyncFlag is a flag for the [File] Sync method.