The sqlite package now exposes a broad safe Go API generated from sqlite3.h, including Go callbacks. The project layout is simpler, and the README is rewritten for library users.
Breaking changes
sqlite.Openreturns*sqlite.Conninstead of thesqlite.DBinterface.sqlite.DBis removed.Conn.Prepare,Conn.QueryandConn.Execreturn the concrete types*sqlite.Stmt,*sqlite.Rowsand*sqlite.Result.- Mockable interfaces live in
sqlite/sqliteiface. Usesqliteiface.Wrap(conn)to get asqliteiface.DB. The mocks insqlite/mocksuse these interfaces. - Go 1.27 or later is required (was 1.26).
New
- Generated safe API:
Conn,Stmt,Blob,Backup,ContextandValuemethods with Go errors, strings, out-parameters and handle lifetimes. - Errors: sentinels for every primary and extended result code (
ErrBusy,ErrConstraintPrimaryKey, …). They work witherrors.Isanderrors.As(*sqlite.Error).ErrNotAvailableis returned when the loaded SQLite lacks a function. - Blobs and backup: incremental blob I/O (
BlobOpen,Read,Write,Reopen) and online backup (Conn.Backup,Step). - Operations:
WALCheckpoint,WALAutoCheckpoint,LoadExtension,Limit,TxnState, status counters, and expanded and normalized SQL. - Go callbacks:
CreateFunction,CreateAggregate,CreateCollation,ExecFunc,BusyHandler,BusyTimeout,CommitHook,RollbackHook,UpdateHook,ProgressHandlerandSetAuthorizer. A panic in a callback is recovered and returned as a*sqlite.CallbackPanicErrorby the call that ran it. OpenFlags: explicitSQLITE_OPEN_*flags and VFS selection.Openusessqlite3_open_v2and acceptsfile:URIs.
Not supported yet
- Window functions written in Go
- Virtual tables
trace_v2,wal_hook,preupdate_hook- Session and changeset
serialize/deserialize- UTF-16 APIs
cmd/sqlitegen/coverage_gen.tsv lists the status of every C function.
Install
go get bnema.dev/purego-sqlite@v0.3.0
Requires Linux, CGO_ENABLED=0, and libsqlite3.so or libsqlite3.so.0 at runtime.