• Stars
    star
    133
  • Rank 263,985 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created over 1 year ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go bindings to SQLite using Wazero

Go bindings to SQLite using Wazero

Go Reference Go Report Go Coverage

Go module github.com/ncruces/go-sqlite3 is cgo-free SQLite wrapper.
It provides a database/sql compatible driver, as well as direct access to most of the C SQLite API.

It wraps a WASM build of SQLite, and uses wazero as the runtime.
Go, wazero and x/sys are the only runtime dependencies.

Packages

Extensions

Advanced features

Caveats

This module replaces the SQLite OS Interface (aka VFS) with a pure Go implementation. This has benefits, but also comes with some drawbacks.

Write-Ahead Logging

Because WASM does not support shared memory, WAL support is limited.

To work around this limitation, SQLite is patched to always use EXCLUSIVE locking mode for WAL databases.

Because connection pooling is incompatible with EXCLUSIVE locking mode, to use the database/sql driver with WAL mode databases you should disable connection pooling by calling db.SetMaxOpenConns(1).

File Locking

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

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

On BSD Unixes, this module uses BSD locks. On BSD Unixes, BSD locks are fully compatible with POSIX advisory locks.

On Windows, this module uses LockFile, LockFileEx, and UnlockFile, like SQLite.

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

Testing

The pure Go VFS is tested by running SQLite's mptest on Linux, macOS, Windows and FreeBSD. Performance is tested by running speedtest1.

Alternatives