mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
35265271aa608dd15b8ba9cee9db2443cbd4a0a4
Go bindings to SQLite using Wazero
⚠️ Work in Progress ⚠️
Go module github.com/ncruces/go-sqlite3 wraps a WASM build of SQLite,
and uses wazero to provide cgo-free SQLite bindings.
- Package
github.com/ncruces/go-sqlite3wraps the C SQLite API (example usage). - Package
github.com/ncruces/go-sqlite3/driverprovides adatabase/sqldriver (example usage). - Package
github.com/ncruces/go-sqlite3/embedembeds a build of SQLite into your application.
Caveats
Because WASM does not support shared memory, WAL support is limited.
To work around this limitation, SQLite is compiled with
SQLITE_DEFAULT_LOCKING_MODE=1,
making EXCLUSIVE the default locking mode.
For non-WAL databases, NORMAL locking mode can be activated with
PRAGMA locking_mode=NORMAL.
Because connection pooling is incompatible with EXCLUSIVE locking mode,
the database/sql driver defaults to NORMAL locking mode,
and WAL databases are not supported.
Roadmap
- build SQLite using
zig cc --target=wasm32-wasi :memory:databases- port
test_demovfs.cto Go- branch
wasiusestest_demovfs.cdirectly
- branch
- design a nice API, enough for simple use cases
- provide a simple
database/sqldriver - file locking, compatible with SQLite on macOS/Linux/Windows
- advanced SQLite features
- nested transactions
- incremental BLOB I/O
- online backup
- snapshots
- session extension
- resumable bulk update
- shared cache mode
- custom SQL functions
- custom VFSes
- read-only VFS, wrapping an
io.ReaderAt - in-memory VFS, wrapping a
bytes.Buffer - cloud-based VFS, based on Cloud Backed SQLite
- custom VFS API
- read-only VFS, wrapping an
Alternatives
Languages
Go
89.9%
C
5.2%
WebAssembly
3.5%
Shell
1.4%