Pure-Go SQLite, no cgo
The repository you are currently viewing might be a mirror. Please review the guidelines below based on where you are viewing this:
| Platform |
Role |
Contributing Guidelines |
| GitLab |
Primary Source |
This is the canonical repository (cznic/sqlite). CI pipelines and main development happen here. |
| GitHub |
Mirror |
This is a mirror (modernc-org/sqlite). We do accept Issues and Pull Requests here for your convenience! Note: PRs submitted here will be manually merged into the GitLab source, so please allow extra time for processing. |

Github Sponsors Account / j-modernc-org
Tailscale
exe.dev
October Swimmer
The SQLite Drivers Benchmarks Game
Changelog
Release notes are kept in CHANGELOG.md.
Contributing
CONTRIBUTING.md covers where to send a merge request or pull
request, how to build and test, and the one thing that is not obvious from the
tree: most of the Go here is generated from C and edits to it are lost at the
next re-vendoring.
Security
Please report a vulnerability privately rather than in a public issue.
SECURITY.md names three private channels, says what is in scope
– including transpilation faults, the bug class unique to a project that ships
SQLite’s C as generated Go – and describes the disclosure path, which includes
filing the advisory with the Go vulnerability database so that govulncheck
reports it.
Licensing
This package is BSD-3-Clause (LICENSE). It also carries a large body of
third-party code: SQLite itself, which is public domain (LICENSE-SQLITE),
the sqlite-vec extension, MIT (LICENSE-SQLITE_VEC), and the Go
module dependency graph.
LICENSE-3RD-PARTY.md accounts for all of it, transitively and
in full text, and separates what is linked into your binary from what merely appears in
the module graph.
A machine-readable SBOM ships beside it: sbom.cdx.json (CycloneDX 1.6)
and sbom.spdx.json (SPDX 2.3), with SBOM.md explaining
what they cover. They name the transpiled SQLite and sqlite-vec C that no Go module
graph reports, which is the part a stock SBOM tool gets wrong about this project.
All four are generated from the tree by make sbom; do not edit them by hand.
Virtual Tables (vtab)
The driver exposes a Go API to implement SQLite virtual table modules in pure Go via the modernc.org/sqlite/vtab package. This lets you back SQL tables with arbitrary data sources (e.g., vector indexes, CSV files, remote APIs) and integrate with SQLite’s planner.
- Register:
vtab.RegisterModule(db, name, module). A nil db registers on the driver this package registers as sqlite, whose modules reach every connection in the process; a non-nil db registers on the driver backing it, so a db opened on a caller-constructed sqlite.Driver keeps its modules to that driver’s connections. Registration applies to new connections only.
- Schema declaration: Call
ctx.Declare("CREATE TABLE <name>(<cols...>)") within Create or Connect. The driver does not auto-declare schemas, enabling dynamic schemas.
- Module arguments:
args []string passed to Create/Connect are configuration parsed from USING module(...). They are not treated as columns unless your module chooses to.
- Planning (BestIndex):
- Inspect
info.Constraints (with Column, Op, Usable, 0-based ArgIndex, and Omit), info.OrderBy, and info.ColUsed (bitmask of referenced columns).
- Set
ArgIndex (0-based) to populate Filter’s vals in the chosen order; set Omit to ask SQLite not to re-check a constraint you fully handle.
- Execution:
Cursor.Filter(idxNum, idxStr, vals) receives arguments in the order implied by ArgIndex.
- Operators: Common SQLite operators map to
ConstraintOp (EQ/NE/GT/GE/LT/LE/MATCH/IS/ISNOT/ISNULL/ISNOTNULL/LIKE/GLOB/REGEXP/FUNCTION/LIMIT/OFFSET). Unknown operators map to OpUnknown.
- Errors: Returning an error from vtab methods surfaces a descriptive message to SQLite (e.g.,
zErrMsg for xCreate/xConnect/xBestIndex/xFilter; sqlite3_result_error for xColumn).
Examples
See vtab package docs for full API details.
Generated sources (deduplication)
The transpiled SQLite C amalgamation in lib/ and the sqlite-vec extension in
vec/ ship one generated Go file per GOOS/GOARCH. Declarations that are
byte-identical across targets are folded into build-tagged shared files —
lib/sqlite.go plus lib/sqlite_g_<hex>.go (and vec/vec.go plus
vec/vec_g_<hex>.go) — by modernc.org/undup,
wired into make vendor. Go’s build constraints make every target compile exactly
the same set of declarations as before, so this is purely a packaging change: it
keeps each tag’s module download well under Go’s 500 MB cap and does not
affect the public API or behavior.
To read or debug a single target’s full, self-contained generated source, expand
the tree back to one complete file per target:
go run modernc.org/[email protected] -expand -dir lib # writes full lib/sqlite_<goos>_<goarch>.go
go run modernc.org/[email protected] -expand -dir vec # writes full vec/vec_<goos>_<goarch>.go
This removes the shared *_g_*.go files and rewrites each
*_<goos>_<goarch>.go as a standalone file — convenient for grepping, reading, or
stepping through one platform’s code. Restore the committed, deduplicated form
with git checkout -- lib vec, or re-fold in place with
go run modernc.org/[email protected] -dir lib (and -dir vec). Hand-written platform
files (libsqlite3_*.go, hooks_*.go, …) carry no generated-code marker and are
never touched by either step.
评论