Getting started
Install
Section titled “Install”go get gosqlite.orgNo CGo, no C toolchain, no apk add. It builds in golang:alpine and distroless images out of the box, and cross-compiles like any pure-Go module.
Your first query
Section titled “Your first query”package main
import ( "database/sql" "log"
_ "gosqlite.org" // registers the "sqlite" and "sqlite3" drivers)
func main() { db, err := sql.Open("sqlite", "file:app.db") if err != nil { log.Fatal(err) } defer db.Close()
if _, err := db.Exec(`CREATE TABLE t (id INTEGER PRIMARY KEY, name TEXT)`); err != nil { log.Fatal(err) } // ... db.Query / db.Exec / db.BeginTx as usual.}db is a standard *sql.DB; everything in database/sql works. The runnable version is examples/getting-started/database-sql/.
Which driver name?
Section titled “Which driver name?”The package registers under two names, same singleton driver:
"sqlite"— modernc-compatible. Use it for new code."sqlite3"— mattn-compatible. Use it when migrating mattn code so the rest stays unchanged.
See Driver names for the full story and Migrating for per-package recipes.
A production preset, no DSN string
Section titled “A production preset, no DSN string”import sqlite "gosqlite.org"
db, _ := sqlite.OpenWAL("app.db") // WAL + busy_timeout=5s + foreign_keys=ondefer db.Close()// db embeds *sql.DB — every database/sql method works.The four open shortcuts (OpenInMemory / OpenWAL / OpenReadOnly / OpenShared), the typed sqlite.Config, and typed pragma enums are covered in Configuration.
Why CGo-free
Section titled “Why CGo-free”Because it transpiles SQLite to Go (via modernc.org/sqlite) instead of binding the C library, you get static, dependency-free binaries; trivial cross-compilation (GOOS=… GOARCH=… go build); reproducible builds with no system SQLite version skew; and no CGo build flags, C compiler, or musl/glibc juggling. The trade-off is on hot UDF callback paths — see Performance.
Next steps
Section titled “Next steps”- Configuration — structured setup the modern way.
- Migrating — coming from another package.
- The docs home lists every guide, the extension catalog, and the reference pages.