# Description Upgrades ncruces/go-sqlite3 to 0.26 which includes SQLite 3.50. ## Checklist Please put an x inside each checkbox to indicate that you've read and followed it: `[ ]` -> `[x]` If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want). - [x] I/we have read the [GoToSocial contribution guidelines](https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CONTRIBUTING.md). - [ ] I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat. - [x] I/we have not leveraged AI to create the proposed changes. - [ ] I/we have performed a self-review of added code. - [ ] I/we have written code that is legible and maintainable by others. - [ ] I/we have commented the added code, particularly in hard-to-understand areas. - [ ] I/we have made any necessary changes to documentation. - [ ] I/we have added tests that cover new code. - [ ] I/we have run tests and they pass locally with the changes. - [ ] I/we have run `go fmt ./...` and `golangci-lint run`. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4218 Co-authored-by: Daenney <daenney@noreply.codeberg.org> Co-committed-by: Daenney <daenney@noreply.codeberg.org>
6.3 KiB
Go bindings to SQLite using wazero
Go module github.com/ncruces/go-sqlite3 is a 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 direct dependencies.
Getting started
Using the database/sql driver:
import "database/sql"
import _ "github.com/ncruces/go-sqlite3/driver"
import _ "github.com/ncruces/go-sqlite3/embed"
var version string
db, _ := sql.Open("sqlite3", "file:demo.db")
db.QueryRow(`SELECT sqlite_version()`).Scan(&version)
Packages
github.com/ncruces/go-sqlite3wraps the C SQLite API (example).github.com/ncruces/go-sqlite3/driverprovides adatabase/sqldriver (example).github.com/ncruces/go-sqlite3/embedembeds a build of SQLite into your application.github.com/ncruces/go-sqlite3/vfswraps the C SQLite VFS API and provides a pure Go implementation.github.com/ncruces/go-sqlite3/gormliteprovides a GORM driver.
Advanced features
- incremental BLOB I/O (example)
- nested transactions (example)
- custom functions (example)
- virtual tables (example)
- custom VFSes (examples)
- online backup (example)
- JSON support (example)
- math functions
- full-text search
- geospatial search
- Unicode support
- statistics functions
- encryption at rest
- many extensions
- and more…
Caveats
This module replaces the SQLite OS Interface (aka VFS) with a pure Go implementation, which has advantages and disadvantages. Read more about the Go VFS design here.
Because each database connection executes within a Wasm sandboxed environment, memory usage will be higher than alternatives.
Testing
This project aims for high test coverage. It also benefits greatly from SQLite's and wazero's thorough testing.
Every commit is tested on:
- Linux: amd64, arm64, 386, riscv64, ppc64le, s390x
- macOS: amd64, arm64
- Windows: amd64
- BSD:
- FreeBSD: amd64, arm64
- OpenBSD: amd64
- NetBSD: amd64, arm64
- DragonFly BSD: amd64
- illumos: amd64
- Solaris: amd64
Certain operating system and CPU combinations have some limitations. See the support matrix for a complete overview.
The Go VFS is tested by running SQLite's mptest.
Performance
Performance of the database/sql driver is
competitive with alternatives.
The Wasm and VFS layers are also benchmarked by running SQLite's speedtest1.
Concurrency
This module behaves similarly to SQLite in multi-thread mode: it is goroutine-safe, provided that no single database connection, or object derived from it, is used concurrently by multiple goroutines.
The database/sql API is safe to use concurrently,
according to its documentation.
FAQ, issues, new features
For questions, please see Discussions.
Also, post there if you used this driver for something interesting ("Show and tell"), have an idea…
The Issue tracker is for bugs, and features we're working on, planning to work on, or asking for help with.