sqlite

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 22 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

SQLite driver for Go

The fastest cgo-free SQLite driver out there, fully compatible with Go's database/sql.
Real-time backup to Cloudflare R2 built in keeps your app stable and reliable on a single VPS.
Concurrent writes wait their turn, so database is locked means real overload, never bad luck.

English · 简体中文 · Benchmarks · How it works · Principles

Go Reference test CGO off Not backed by Y Combinator Users unknown

It is for Go programs that keep their data in SQLite and want to stay plain Go: one static binary, cross-compiled from any machine, no C compiler in the build or in the container. Until now that meant giving up speed. Here the cgo driver is the one that falls behind.

liustack/sqlite is at v0.1. The APIs may still change before v1.

What stops you from running SQLite on a server?

The worry Measured
database is locked 256 goroutines writing for 30 s: 0 locked, mattn 273 (how)
One writer at a time 64 goroutines, synchronous=FULL: 57,966 writes/s, mattn 868 (group commit)
Data on one machine Every commit is in R2 about a second later. A new machine goes on where the old one stopped, and a bad deploy rewinds to the second before it (replication)
cgo No cgo, no C compiler, and reading one row by key takes 3.83 µs, mattn (cgo) 7.45 µs (benchmarks)

Measured on linux/amd64, AMD EPYC 7B13, 4 cores. What is left is your app.

Why it exists

While building Tifa, I wanted every app to deploy as one Go binary copied to a small VPS. The data had to live in SQLite, and CGO had to stay off, or there goes cross-compiling and the scratch image.

The pure Go drivers paid for that in speed. modernc translates SQLite's C into Go and ncruces runs it as WebAssembly, and both trailed the cgo driver. So I had LLVM compile SQLite's own C straight into Go assembly, and kept at it until the cgo driver was the one falling behind.

Benchmarks

Time per operation, lower is better, the median of 6 runs. The best of a row is in bold when its 95% confidence interval overlaps no other driver's. WAL, synchronous=NORMAL, the same settings checked on every driver.

linux/amd64 (AMD EPYC 7B13, Go 1.27.4, commit 0d24c63):

Workload liustack/sqlite mattn (cgo) modernc ncruces
Insert one row 22.9 µs 23.5 µs 26.9 µs 24.6 µs
Insert 1000 rows in a transaction 1.45 ms 1.67 ms 2.21 ms 1.88 ms
Read one row by key 3.83 µs 7.45 µs 9.39 µs 7.23 µs
Read 100k rows 35.6 ms 83.3 ms 79.1 ms 54.6 ms
Join and group 2.84 ms 2.87 ms 4.99 ms 4.82 ms
Find a user with 400 comments 518 µs 897 µs 1.13 ms 826 µs
Read 100 rows of 200 KB text 8.97 ms 8.13 ms 9.31 ms 9.30 ms
Read by key, 4 threads 1.51 µs 2.64 µs 3.72 µs 2.51 µs
Insert, 8 goroutines at once 10.4 µs 20.6 µs 25.9 µs 24.0 µs
Insert, 64 goroutines at once 3.36 µs 22.6 µs 30.5 µs 29.2 µs
Insert, 64 goroutines, synchronous=FULL 31.1 µs 4.77 ms 6.27 ms 1.48 ms

darwin/arm64 (Apple M4, Go 1.27.2, commit 0d24c63):

Workload liustack/sqlite mattn (cgo) modernc ncruces
Insert one row 6.02 µs 6.01 µs 7.29 µs 6.94 µs
Insert 1000 rows in a transaction 472 µs 548 µs 731 µs 588 µs
Read one row by key 1.11 µs 1.94 µs 2.78 µs 2.03 µs
Read 100k rows 13.8 ms 29.9 ms 30.0 ms 20.4 ms
Join and group 1.26 ms 1.14 ms 2.67 ms 1.85 ms
Find a user with 400 comments 215 µs 368 µs 559 µs 341 µs
Read 100 rows of 200 KB text 3.51 ms 3.38 ms 3.74 ms 3.58 ms
Read by key, 10 threads 1.15 µs 1.51 µs 1.75 µs 2.31 µs
Insert, 8 goroutines at once 3.04 µs 6.87 µs 8.07 µs 40.5 µs
Insert, 64 goroutines at once 1.16 µs 9.68 µs 9.70 ms 81.7 µs

Against SQLite in C on the same machine: SQLite(C) is a C program calling SQLite itself, liustack/sqlite(direct) calls the driver without database/sql, and the two database/sql columns read and write as a program would. Many writers at once go faster because the driver merges their commits into one.

linux/amd64 (AMD EPYC 7B13, Go 1.27.4, commit 0d24c63):

Throughput. Reads or writes done per second by all threads together, on a file of 100k rows in WAL mode, higher is better:

Benchmark SQLite(C) liustack/sqlite(direct) liustack/sqlite(database/sql) mattn(database/sql)
1 thread, each reads one row by key 194k reads/s ±1% 376k reads/s ±2% 292k reads/s ±3% 103k reads/s ±2%
8 threads, each reads one row by key 1198k reads/s ±11% 1351k reads/s ±3% 1039k reads/s ±4% 450k reads/s ±4%
64 threads, each reads one row by key 1158k reads/s ±5% 1357k reads/s ±4% 990k reads/s ±5% 462k reads/s ±5%
1 thread, each reads one row by key, whole file in cache 244k reads/s ±1% 733k reads/s ±4% 488k reads/s ±3% 116k reads/s ±1%
8 threads, each reads one row by key, whole file in cache 1662k reads/s ±13% 2404k reads/s ±4% 1602k reads/s ±4% 499k reads/s ±5%
64 threads, each reads one row by key, whole file in cache 1375k reads/s ±9% 2225k reads/s ±6% 1405k reads/s ±5% 364k reads/s ±5%
8 threads read as above while 8 others write 1191k reads/s ±5% 1104k reads/s ±6% 689k reads/s ±4% 171k reads/s ±3%
8 threads, each inserts one row, while 8 others read 2006 writes/s ±33% 17122 writes/s ±20% 25689 writes/s ±15% 15926 writes/s ±3%
64 threads, each inserts one row, synchronous=FULL 857 writes/s ±3% 58543 writes/s ±4% 57966 writes/s ±4% 868 writes/s ±2%

Where another driver still wins: work that stays inside SQLite (the join), where this driver runs the same C but as Go assembly, and reading large text values. Why reads and many writers are faster, the versions of each driver, and how to run it all again are in docs/benchmarks.md.

Concurrent writes without database is locked

SQLite lets one connection write at a time. With other drivers the rest race for the lock in SQLite's busy handler, and one that keeps losing gives up with database is locked after busy_timeout, at a load where the others wait a few milliseconds. Here the writers of one process wait their turn in order, so a write gets database is locked only when the writes queued ahead of it take longer than the busy timeout (5 s by default), that is, only when writes come faster than the disk can commit them.

Open the database, and that is all there is to set:

db, err := sqlite.Open("app.db")

The driver puts the file in WAL mode, where readers and the writer do not wait for each other, and starts a transaction with BEGIN IMMEDIATE.

  • A write on its own (db.Exec of an INSERT, UPDATE or DELETE) needs nothing more. Writes that come at the same time are committed together.

  • A transaction that reads and then writes waits its turn for the write lock at BEGIN, so it never fails halfway:

    func buy(ctx context.Context, db *sql.DB, item, qty int) error {
    	tx, err := db.BeginTx(ctx, nil) // waits here for the write lock
    	if err != nil {
    		return err
    	}
    	defer tx.Rollback()
    	var stock int
    	if err := tx.QueryRowContext(ctx, `SELECT stock FROM items WHERE id = ?`, item).Scan(&stock); err != nil {
    		return err
    	}
    	if stock < qty {
    		return errSoldOut
    	}
    	if _, err := tx.ExecContext(ctx, `UPDATE items SET stock = stock - ? WHERE id = ?`, qty, item); err != nil {
    		return err
    	}
    	return tx.Commit()
    }
    

    SQLite on its own starts a transaction as a reader, and its first write fails at once with database is locked when another connection holds the write lock or has committed since it read. A longer timeout does not help. _txlock=deferred in the name of the database gives that back.

  • Tip: mark a transaction that only reads. db.BeginTx(ctx, &sql.TxOptions{ReadOnly: true}) takes no write lock and waits for no writer. Reads outside a transaction (db.Query) need nothing. A plain db.Begin() takes the write lock at BEGIN, even if it then only reads: until it ends, every writer waits for it, and so does every other transaction started that way. A long one, as a report, makes them fail with database is locked once they have waited 5 seconds.

When it can still come, and what to do then: database is locked.

linux/amd64 (AMD EPYC 7B13, Go 1.27.4, commit 0d24c63):

The slowest write (a transaction, or an autocommit statement), and how many writes got database is locked, in 30 s of each:

Workload liustack/sqlite mattn (cgo) modernc ncruces
Insert one row, 64 goroutines at once 13.4 ms 3.83 s 2.83 s 77.6 ms
Transactions, 64 goroutines, _txlock=immediate 27.4 ms 4.93 s 4.43 s 197 ms
Transactions, 64 goroutines, immediate, 2 ms of work in each 164 ms 5.01 s, 35 locked 5.01 s, 19 locked 1.52 s
Transactions, 64 goroutines, immediate, synchronous=FULL 101 ms 5.01 s, 266 locked 5.01 s, 252 locked 3.72 s
Transactions, 256 goroutines, immediate, 1 ms of work in each 330 ms 5.01 s, 273 locked 5.02 s, 244 locked 4.85 s

A transaction here reads two rows and updates them, and the work inside it holds the write lock. The cases, the median and the writes per second are in docs/benchmarks.md.

Real-time backup to S3

Your data outlives the machine. Every commit is in R2 about a second later, so if the VPS disappears, a new one is back where it stopped, and if a deploy deletes the wrong rows, you rewind to the second before it. On R2 it usually stays in the free tier.

Start the replicator before you open the database, and every commit goes to S3, Cloudflare R2 or MinIO about a second later:

cfg := replica.Config{
	URL: "s3://my-bucket/app.db?endpoint=https://<account>.r2.cloudflarestorage.com&region=auto",
}
r, err := replica.New(ctx, "app.db", cfg)
if err != nil {
	return err
}
defer r.Close()

db, err := sqlite.Open("app.db")

On a new machine one call brings the database back, as it is now or as it was at an earlier time, at least a day back by default:

txid, err := replica.Restore(ctx, "app.db", cfg, replica.RestoreOptions{})
  • Writes never wait for the upload. A slow or unreachable store never slows a write or makes it fail. Changes wait on disk next to the database and go up once the store answers.
  • Nothing else to deploy. It is a package in your program, so the deploy stays one binary, with no Litestream process beside it.
  • Every file is checked on restore, then PRAGMA integrity_check runs, and a database already there is never written over.
  • Litestream reads the same copy. It is laid out as Litestream lays it out, and the tests have litestream restore rebuild it at every point and check it gives the same bytes.
  • r.Sync(ctx) waits until what you committed is in the store, for the writes that must be safe before you go on.

Settings, how far behind the copy is, and its limits: Replication.

Install

go get github.com/liustack/sqlite

Go 1.26.6 to 1.27 (see Moving to a new Go). linux, darwin and windows, on amd64 and arm64.

Use

import "github.com/liustack/sqlite"

db, err := sqlite.Open("app.db")

db is a *sql.DB of database/sql, and what a server needs is already chosen:

  • WAL mode, so readers and the writer do not wait for each other. The mode stays in the file, and the latest commits are in app.db-wal beside it: a copy of app.db alone can miss them, so back up with VACUUM INTO or the backup built in. A file that cannot be converted, as one in a directory that cannot be written, opens in the mode it has. Every program that opens the file must run on the same machine, so WAL is not for a file on a network disk: _pragma=journal_mode(delete) keeps SQLite's rollback journal.
  • BEGIN IMMEDIATE, so a transaction waits its turn for the write lock (see Concurrent writes without database is locked). Start a transaction that only reads with sql.TxOptions{ReadOnly: true}.
  • 5 seconds of waiting for a lock before database is locked.
  • synchronous=FULL, SQLite's own setting: a commit is synced to the disk before the call returns. On macOS a sync does not make the drive write out its cache, which _pragma=fullfsync(1) does.
  • A pool of up to 128 connections, kept when idle and closed after 5 idle minutes. database/sql on its own keeps 2 and has no limit, so with more goroutines it closes and opens connections all the time, and a burst of requests opens a connection each, with a page cache of up to 2 MB each.

sql.Open("sqlite", "app.db") opens the same database with the pool of database/sql. When a library opens the *sql.DB for you, sqlite.OptimizePool(db) gives it the pool of Open.

The name is a file, :memory: or a SQLite URI. To choose otherwise, say so in the name: _pragma=name(value) runs a PRAGMA on every new connection (file:app.db?_pragma=synchronous(NORMAL), or _pragma=journal_mode(delete) for a rollback journal), and _txlock=deferred starts transactions as SQLite does. What you set on db afterwards holds too: writes that come at the same time are committed together only when each has a connection, so a program with more than 128 goroutines writing at once writes more with a larger pool (db.SetMaxOpenConns(256) and db.SetMaxIdleConns(256)), at 2 MB more for each connection that reads. The rest is on pkg.go.dev.

SQLite picks how to run a query from statistics that only ANALYZE gathers, and it does not update them as the data changes. Let PRAGMA optimize keep them: run db.Exec("PRAGMA optimize=0x10002") once at start, and db.Exec("PRAGMA optimize") now and then (once a day, and after CREATE INDEX). It analyzes only the tables that need it, from a sample of each index, and holds the write lock while it does, so its first run on a large database that never had statistics can keep writes waiting for seconds. A full ANALYZE gives the best statistics and reads the whole database under the write lock: run it when nothing writes. _pragma=optimize is refused, as it would run each time a connection opens.

An error from SQLite is a *sqlite.Error. errors.As gets it, and Code() and ExtendedCode() give its result code, as sqlite.BUSY or sqlite.CONSTRAINT_UNIQUE.

SQL functions, aggregates, window functions, collations and virtual tables written in Go are given as the database is opened, so that every connection of the pool has them:

db, err := sqlite.Open("app.db",
	sqlite.WithFunction("reverse", 1, reverse, sqlite.Deterministic),
	sqlite.WithAggregate("mode", 1, newMode),
	sqlite.WithCollation("fold", fold),
	sqlite.WithModule("files", connectFiles))

sqlite.Register gives them to every database opened after it, with sql.Open too. An error or a panic in a function or a virtual table fails its statement, not the connection.

Common functions come ready in packages under ext/: regexp (the REGEXP operator, regexp_like, regexp_substr, regexp_replace), uuid, hash (md5, sha1, sha256, sha512, crc32), stats (variance and standard deviation), unicode (upper and lower case and a case-blind collation for every script), csv (a CSV file as a table), series (generate_series) and vec (vector distances, to find the rows nearest to an embedding). Each is one option, and sqlite.Join hands several over as one:

sqlite.Register(sqlite.Join(regexp.Option(), uuid.Option()))

Full-text search (FTS5), the spatial index (R*Tree), the math functions and median and percentile (percentile) are built in, with nothing to import. The math functions give the same bits on every target.

The driver registers as sqlite, as modernc.org/sqlite and glebarez/go-sqlite do, so a program that imports one of them as well panics at start.

What changes for you

  • No C anywhere. CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build from a Mac works, and the binary runs in a scratch image.
  • Many writers stop waiting on each other. When goroutines write at the same time, the driver runs their autocommit INSERT, UPDATE and DELETE statements as one transaction and commits once. Each call still gets its own error, LastInsertId and RowsAffected, and returns only after the commit, so nothing is less durable. When one statement fails so badly that SQLite rolls back the whole transaction (an IO error, ON CONFLICT ROLLBACK, a context that ends while it runs), the statements merged before it fail with ABORT_ROLLBACK, and none runs twice. Transactions you open yourself are never merged. The rules
  • Writers queue instead of failing with database is locked. Inside the driver one connection of your program writes a file at a time, and the others queue for it, up to busy_timeout, instead of sleeping in SQLite's busy handler. A transaction that reads first and writes later can still fail when another wrote in between, which is why the driver starts a transaction with BEGIN IMMEDIATE unless _txlock=deferred says otherwise. Other processes still meet SQLite's own locks.
  • Reads cost less. A call into SQLite is a plain Go call, and on Go 1.27 scanning a number into your variable allocates nothing (a string costs one allocation, its own).
  • Real-time backup is built in. Every commit reaches S3, R2 or MinIO about a second later, from inside your program. See Real-time backup to S3.

Why you can trust it

  • Tifa builds on it. Apps made with tifa new, from Tifa, the full-stack Go framework, keep their data in this driver.
  • Safety comes first, speed second, memory third. A change that is faster but could lose a write, return a wrong result or weaken a commit is not taken. Group commit keeps a SAVEPOINT around every merged statement for this reason, though it costs speed.
  • The C is SQLite's, unchanged. engine/ holds the 3.54.1 amalgamation as released, checked against its hash (engine/vendor.sh --verify). The compile options sit in one file, each with its reason.
  • The Go assembly is made, never written. LLVM compiles the C, and a generator turns what LLVM writes into Go assembly. It stops on anything it has no rule for, and checks the linked binary. make check-gen fails when the checked-in assembly is not what the generator makes from engine/ today.
  • The numbers show where it loses. The tables above keep the rows where another driver is faster, and docs/benchmarks.md says how each run was taken and what else ran on the machine.
  • Every push is tested on linux/amd64, linux/arm64, darwin/arm64, windows/amd64 and windows/arm64 (with the race detector, except on windows), with the sqlite3 shell writing the same database at the same time, and with processes killed while they write.

Left out on purpose

  • No loadable extensions: SQLite is built without load_extension, as the engine is Go assembly with nothing to load a C library into. Built in instead: JSON, FTS5 (full-text search), R*Tree, the math functions and median and percentile, all compiled into the engine. The packages of ext/ add regexp, uuid, hash, stats, unicode, csv, series and vec, and sqlite.WithFunction adds functions of your own in Go (Use).
  • No shared cache: cache=shared gives an error. SQLite calls shared cache obsolete and advises WAL in its place. Connections that share a cache lock each other at the level of tables and get database table is locked, and leaving it out of the build makes SQLite faster. For a memory database that all connections of a pool see, use file:/name?vfs=memdb.
  • Double-quoted strings are identifiers only (SQLITE_DQS=0, as SQLite advises): write string literals in single quotes. SQL moved from mattn/go-sqlite3 or modernc.org/sqlite that writes WHERE name = "bob" gets no such column: "bob". Those drivers read "bob" as text when no column has that name, so a column name spelled wrong turns into a string, and the query gives a wrong result with no error.
  • Other targets (freebsd, 32-bit, riscv64, ...) do not build: the build stops with an error that names the supported ones.

Documentation

Doc Read it when
Principles You want to know what the driver promises, what it cannot, and what it will not trade for speed
Benchmarks You want the full numbers, or to run them on your machine
Architecture You want to know how C becomes Go assembly, or how group commit works
database is locked A write got database is locked, or you want to know how to write transactions so that none does
A WAL that grows The -wal file is large or keeps growing, or your program holds reads open for long
Group commit You want to know which concurrent writes merge, and what error each gets when one fails
Statement cache You want to know which statements the driver keeps for you, and why a kept one never reads something stale
Replication You want a copy of the database in S3, R2 or MinIO, or to restore one
A queue in the database You want to send emails or call webhooks in the background, and not lose one when the process dies
The queue beside RabbitMQ, BullMQ and honker You want to know whether one table in the database is enough, with no RabbitMQ and no Redis
When every core is busy A read or a write waits tens of milliseconds or more now and then, or you run on one core or two
Upstream You want to know which SQLite it is, or how it moves to a new one
Changelog You want to know what a release changed before you upgrade
Testing, Commits You are about to change the code

Talk to us

Issues are welcome any time: open one. Tell us what you built, where it hurt, and what should come next. What changes in the driver and what comes next are shared on X: @liustack.

Contributing

liustack/sqlite does not accept pull requests. A change here can reach from SQLite's C, through the generator, to group commit and the replicator, and getting it right takes a lot of context, so every line is written and reviewed by one author. Two ways to help:

  • Open an issue. Bugs, wrong results, slow queries, confusing errors, unclear docs, ideas. A small program that reproduces it helps more than a patch, and issues shape what gets built next.
  • Fork it. Under MIT your copy is yours to change and publish. CONTRIBUTING.md has the notes for working on a fork.

Security issues go through a private report, not an issue: see SECURITY.md.

Star History

Star History Chart

Thanks

To D. Richard Hipp and the SQLite developers for SQLite, and to musl for the string functions the engine links. To the authors of mattn/go-sqlite3, modernc.org/sqlite and ncruces/go-sqlite3, who showed the ways SQLite can live in Go and whose drivers this one is measured against.

License

MIT for the code of this repository. SQLite is in the public domain, and musl's code keeps its MIT license. NOTICE.md says which license covers which path.

SQLite is a registered trademark of Hipp, Wyrick & Company, Inc., and this project is not affiliated with it. The gopher in the banner is a redrawn Go gopher, originally designed by Renee French and used under CC BY 4.0.

Documentation

Overview

Package sqlite is a SQLite driver for database/sql that needs no cgo.

Open opens a database with what a server needs already chosen:

db, err := sqlite.Open("app.db")

The driver also registers itself as "sqlite", and sql.Open("sqlite", "app.db") opens the same database with the pool of database/sql (OptimizePool gives it the pool of Open). modernc.org/sqlite and github.com/glebarez/go-sqlite register the same name, so a program that imports one of them as well panics at start.

What the driver chooses

A database opened with nothing but its name is not as SQLite alone would open it. The driver chooses when a call waits and where the bytes go, never what a statement returns or whether a commit is on the disk:

  • The file is put in WAL mode (PRAGMA journal_mode=WAL), where readers and the writer do not wait for each other. Not when the DSN has a _pragma=journal_mode of its own (_pragma=journal_mode(delete) for a rollback journal, _pragma=journal_mode to leave the file as it is), and not on a connection that only reads (mode=ro, a file that cannot be written, _pragma=query_only). A file that cannot be put in WAL mode as a connection opens is opened in the mode it has.
  • A transaction starts with BEGIN IMMEDIATE: it waits its turn for the write lock, so one that reads and then writes does not fail halfway with "database is locked". Start a transaction that only reads with sql.TxOptions{ReadOnly: true}, or it holds the write lock while it reads, and the writers that wait for it longer than the busy timeout fail. _txlock=deferred starts transactions as SQLite does, and so does a connection that cannot write (mode=ro, PRAGMA query_only).
  • A connection waits 5 seconds for a lock (busy_timeout).

synchronous is SQLite's FULL, and foreign keys are off, as in SQLite.

The data source name

A file name, ":memory:", or a URI ("file:app.db?mode=ro"), which SQLite reads itself (https://sqlite.org/uri.html). These parameters are the driver's and SQLite does not see them:

  • _pragma=name(value): a PRAGMA run on every new connection, in order. It may be given more than once. Not optimize, which may write: run it with Exec once the database is open.
  • _txlock=immediate, deferred or exclusive: how BEGIN starts a transaction (immediate by default, see above). A read-only transaction always starts deferred, and so does every transaction of a connection SQLite opened read-only, unless _txlock is given.
  • _time_format=sqlite: how a time.Time is written. The only format, and the default, is "2006-01-02 15:04:05.999999999-07:00".
  • _wal_limit=bytes: the length of the WAL past which the driver starts it over, waiting up to 100 ms for the readers that still use it. In WAL mode, reads that overlap without a gap otherwise let the WAL grow as long as they last. 67108864 (64 MiB) by default, 0 for no limit.

In WAL mode the driver runs the automatic checkpoints of its connections: one each time the WAL has grown by wal_autocheckpoint frames, where SQLite runs one after every commit once the WAL is that long. PRAGMA wal_autocheckpoint reads and sets it as before.

Foreign keys in a migration

PRAGMA foreign_keys does nothing inside a transaction (https://sqlite.org/pragma.html#pragma_foreign_keys). So with _pragma=foreign_keys(1), a migration that rebuilds a table as SQLite describes (https://sqlite.org/lang_altertable.html#otheralter) inside a transaction runs with foreign keys on, also when it runs PRAGMA foreign_keys=OFF itself. Its DROP TABLE then deletes, without an error, every row of another table that refers to the table with ON DELETE CASCADE. Migration tools such as goose and golang-migrate run each file in a transaction by default. Turn foreign keys off on a connection of its own before BEGIN, check them before COMMIT, and close that connection so that the pool never hands it out:

conn, err := db.Conn(ctx)
if err != nil {
	return err
}
// Returning driver.ErrBadConn closes conn and takes it out of the pool.
defer conn.Raw(func(any) error { return driver.ErrBadConn })
if _, err := conn.ExecContext(ctx, "PRAGMA foreign_keys=OFF"); err != nil {
	return err
}
tx, err := conn.BeginTx(ctx, nil)
if err != nil {
	return err
}
defer tx.Rollback()
// The migration, then PRAGMA foreign_key_check with tx: any row it
// gives is a reference the migration broke, so return before Commit.
return tx.Commit()

Index

Examples

Constants

View Source
const (
	ERROR      = 1
	INTERNAL   = 2
	PERM       = 3
	ABORT      = 4
	BUSY       = 5
	LOCKED     = 6
	NOMEM      = 7
	READONLY   = 8
	INTERRUPT  = 9
	IOERR      = 10
	CORRUPT    = 11
	NOTFOUND   = 12
	FULL       = 13
	CANTOPEN   = 14
	PROTOCOL   = 15
	EMPTY      = 16
	SCHEMA     = 17
	TOOBIG     = 18
	CONSTRAINT = 19
	MISMATCH   = 20
	MISUSE     = 21
	NOLFS      = 22
	AUTH       = 23
	FORMAT     = 24
	RANGE      = 25
	NOTADB     = 26
	NOTICE     = 27
	WARNING    = 28
)

Primary result codes.

View Source
const (
	ERROR_MISSING_COLLSEQ   = ERROR | 1<<8
	ERROR_RETRY             = ERROR | 2<<8
	ERROR_SNAPSHOT          = ERROR | 3<<8
	ERROR_RESERVESIZE       = ERROR | 4<<8
	ERROR_KEY               = ERROR | 5<<8
	ERROR_UNABLE            = ERROR | 6<<8
	IOERR_READ              = IOERR | 1<<8
	IOERR_SHORT_READ        = IOERR | 2<<8
	IOERR_WRITE             = IOERR | 3<<8
	IOERR_FSYNC             = IOERR | 4<<8
	IOERR_DIR_FSYNC         = IOERR | 5<<8
	IOERR_TRUNCATE          = IOERR | 6<<8
	IOERR_FSTAT             = IOERR | 7<<8
	IOERR_UNLOCK            = IOERR | 8<<8
	IOERR_RDLOCK            = IOERR | 9<<8
	IOERR_DELETE            = IOERR | 10<<8
	IOERR_BLOCKED           = IOERR | 11<<8
	IOERR_NOMEM             = IOERR | 12<<8
	IOERR_ACCESS            = IOERR | 13<<8
	IOERR_CHECKRESERVEDLOCK = IOERR | 14<<8
	IOERR_LOCK              = IOERR | 15<<8
	IOERR_CLOSE             = IOERR | 16<<8
	IOERR_DIR_CLOSE         = IOERR | 17<<8
	IOERR_SHMOPEN           = IOERR | 18<<8
	IOERR_SHMSIZE           = IOERR | 19<<8
	IOERR_SHMLOCK           = IOERR | 20<<8
	IOERR_SHMMAP            = IOERR | 21<<8
	IOERR_SEEK              = IOERR | 22<<8
	IOERR_DELETE_NOENT      = IOERR | 23<<8
	IOERR_MMAP              = IOERR | 24<<8
	IOERR_GETTEMPPATH       = IOERR | 25<<8
	IOERR_CONVPATH          = IOERR | 26<<8
	IOERR_VNODE             = IOERR | 27<<8
	IOERR_AUTH              = IOERR | 28<<8
	IOERR_BEGIN_ATOMIC      = IOERR | 29<<8
	IOERR_COMMIT_ATOMIC     = IOERR | 30<<8
	IOERR_ROLLBACK_ATOMIC   = IOERR | 31<<8
	IOERR_DATA              = IOERR | 32<<8
	IOERR_CORRUPTFS         = IOERR | 33<<8
	IOERR_IN_PAGE           = IOERR | 34<<8
	IOERR_BADKEY            = IOERR | 35<<8
	IOERR_CODEC             = IOERR | 36<<8
	LOCKED_SHAREDCACHE      = LOCKED | 1<<8
	LOCKED_VTAB             = LOCKED | 2<<8
	BUSY_RECOVERY           = BUSY | 1<<8
	BUSY_SNAPSHOT           = BUSY | 2<<8
	BUSY_TIMEOUT            = BUSY | 3<<8
	CANTOPEN_NOTEMPDIR      = CANTOPEN | 1<<8
	CANTOPEN_ISDIR          = CANTOPEN | 2<<8
	CANTOPEN_FULLPATH       = CANTOPEN | 3<<8
	CANTOPEN_CONVPATH       = CANTOPEN | 4<<8
	CANTOPEN_DIRTYWAL       = CANTOPEN | 5<<8
	CANTOPEN_SYMLINK        = CANTOPEN | 6<<8
	CORRUPT_VTAB            = CORRUPT | 1<<8
	CORRUPT_SEQUENCE        = CORRUPT | 2<<8
	CORRUPT_INDEX           = CORRUPT | 3<<8
	READONLY_RECOVERY       = READONLY | 1<<8
	READONLY_CANTLOCK       = READONLY | 2<<8
	READONLY_ROLLBACK       = READONLY | 3<<8
	READONLY_DBMOVED        = READONLY | 4<<8
	READONLY_CANTINIT       = READONLY | 5<<8
	READONLY_DIRECTORY      = READONLY | 6<<8
	ABORT_ROLLBACK          = ABORT | 2<<8
	CONSTRAINT_CHECK        = CONSTRAINT | 1<<8
	CONSTRAINT_COMMITHOOK   = CONSTRAINT | 2<<8
	CONSTRAINT_FOREIGNKEY   = CONSTRAINT | 3<<8
	CONSTRAINT_FUNCTION     = CONSTRAINT | 4<<8
	CONSTRAINT_NOTNULL      = CONSTRAINT | 5<<8
	CONSTRAINT_PRIMARYKEY   = CONSTRAINT | 6<<8
	CONSTRAINT_TRIGGER      = CONSTRAINT | 7<<8
	CONSTRAINT_UNIQUE       = CONSTRAINT | 8<<8
	CONSTRAINT_VTAB         = CONSTRAINT | 9<<8
	CONSTRAINT_ROWID        = CONSTRAINT | 10<<8
	CONSTRAINT_PINNED       = CONSTRAINT | 11<<8
	CONSTRAINT_DATATYPE     = CONSTRAINT | 12<<8
	NOTICE_RECOVER_WAL      = NOTICE | 1<<8
	NOTICE_RECOVER_ROLLBACK = NOTICE | 2<<8
	NOTICE_RBU              = NOTICE | 3<<8
	WARNING_AUTOINDEX       = WARNING | 1<<8
	AUTH_USER               = AUTH | 1<<8
)

Extended result codes.

Variables

View Source
var ErrUnusablePlan = errors.New("sqlite: no usable plan for the virtual table")

ErrUnusablePlan is what BestIndex returns when the scan cannot work with the constraints it was given.

Functions

func Open added in v0.2.0

func Open(dsn string, opts ...Option) (*sql.DB, error)

Open opens the database dsn names, as sql.Open("sqlite", dsn) does, sets up its pool as OptimizePool does, and connects once: a name that cannot be opened fails here and not at the first query.

db, err := sqlite.Open("app.db")

opts are the options NewConnector takes.

func OptimizePool added in v0.2.0

func OptimizePool(db *sql.DB) error

OptimizePool sets up the pool of db, a database of this driver that something else opened, as Open does:

  • At most 128 connections, all of them kept when idle. database/sql keeps 2 and has no limit: with more goroutines than that it closes and opens connections all the time, and a burst of requests opens a connection each, with a page cache each.
  • A connection idle for 5 minutes is closed, so the memory of a burst comes back.
  • A database that lives in one connection (":memory:", a temporary database) gets a pool of one connection that is never closed, so that every call sees the same database. A call made while another holds the connection (rows not yet closed, a transaction) waits for it: use the rows or the transaction for it.
  • No connection is closed for its age (SetConnMaxLifetime).

It connects once to see which database db is, and waits for a connection when the program holds all of them. What the program sets on db afterwards holds. A db whose connections are wrapped by another package (one that traces calls, say) gives an error: OptimizePool cannot see the database behind them.

func Register

func Register(opts ...Option)

Register adds opts to every connector made after it, by sql.Open or by NewConnector, before the connector's own options. Call it before opening databases, as in an init function. An option it was given that is not valid fails those connectors.

Types

type Aggregate

type Aggregate interface {
	Step(args []driver.Value) error
	Final() (driver.Value, error)
}

Aggregate is the state of one group of an aggregate function written in Go. Step runs for each row of the group, with arguments as a Func gets them, then Final once, with a result as a Func gives it. An error or a panic in either is the error of the statement.

type Connector

type Connector struct {
	// contains filtered or unexported fields
}

Connector opens connections to one database.

func NewConnector

func NewConnector(dsn string, opts ...Option) (*Connector, error)

NewConnector parses dsn, for sql.OpenDB. Its connections get what Register gave, then opts.

func (*Connector) Connect

func (c *Connector) Connect(ctx context.Context) (driver.Conn, error)

Connect opens a connection.

func (*Connector) Driver

func (c *Connector) Driver() driver.Driver

Driver is the driver of the connector.

type Driver

type Driver struct{}

Driver is the database/sql driver.

func (*Driver) Open

func (d *Driver) Open(dsn string) (driver.Conn, error)

Open opens a connection to the database named by dsn.

func (*Driver) OpenConnector

func (d *Driver) OpenConnector(dsn string) (driver.Connector, error)

OpenConnector parses dsn once for every connection of a pool.

type Error added in v0.1.5

type Error = csqlite.Error

Error is an error SQLite gave, with its result code. Read it with errors.As:

var e *sqlite.Error
if errors.As(err, &e) && e.Code() == sqlite.CONSTRAINT {
	// a constraint failed
}

Code is the primary result code (CONSTRAINT), ExtendedCode the extended one (CONSTRAINT_UNIQUE), as listed in codes.go and at https://sqlite.org/rescode.html. Unwrap gives the error under it when there is one: the panic of a Go collation, or for ABORT_ROLLBACK under group commit, the error that rolled the batch back.

A statement stopped by its context gives the context's error instead.

type Func

type Func func(args []driver.Value) (driver.Value, error)

Func is a SQL function written in Go.

Its arguments are copies, each an int64, float64, string, []byte or nil, so it may keep them. It returns a value database/sql can bind (an integer, float, bool, string, []byte, time.Time, nil or a driver.Valuer), or an error, which becomes the error of the statement. A panic in it is recovered and becomes the error of the statement too: the connection stays good.

It may run on any connection of its connector, and from several goroutines at once. It must not use the database: it runs in the middle of a statement. It may also run more than once for the same row: SQLite does not promise how often it calls a function. Group commit never runs a statement twice. A statement that called a function not marked Innocuous ends its batch and commits right away, so that a failure of a later statement cannot roll back what it wrote after the function acted.

type FuncFlag

type FuncFlag int

FuncFlag tells SQLite how a function behaves.

const (
	// Deterministic: the same arguments always give the same result, so
	// SQLite may compute it once, and use it in indexes and generated
	// columns.
	Deterministic FuncFlag = csqlite.FuncDeterministic
	// DirectOnly: the function may be called only from SQL the program
	// runs, never from a trigger, view, index or generated column of the
	// schema. Give it to a function with side effects, so that a database
	// file someone else made cannot call it.
	DirectOnly FuncFlag = csqlite.FuncDirectOnly
	// Innocuous: the function has no side effects and reveals nothing, so
	// it is safe wherever SQL comes from. A write that calls only such
	// functions merges with others: one that calls a Go function without
	// this flag ends its group commit batch.
	Innocuous FuncFlag = csqlite.FuncInnocuous
)

type IndexConstraint added in v0.1.3

type IndexConstraint struct {
	Column int // -1 for the rowid
	Op     IndexOp
	Usable bool
}

IndexConstraint is a term of the WHERE clause: column Op value. A constraint that is not Usable may not get an ArgvIndex.

type IndexInfo added in v0.1.3

type IndexInfo struct {
	Constraints []IndexConstraint
	OrderBy     []IndexOrderBy
	// ColUsed has bit i set when the statement uses column i, and bit 63
	// for any column from 63 up.
	ColUsed uint64

	// Usage is as long as Constraints, one for each.
	Usage []IndexUsage
	// IdxNum and IdxStr name the plan for Filter.
	IdxNum int
	IdxStr string
	// OrderByConsumed says the scan gives its rows in the order of OrderBy.
	OrderByConsumed bool
	EstimatedCost   float64
	EstimatedRows   int64
	// Unique says the scan gives at most one row.
	Unique bool
}

IndexInfo is the question BestIndex answers. Constraints, OrderBy and ColUsed are the question. The rest is the answer, with SQLite's defaults in EstimatedCost and EstimatedRows.

type IndexOp added in v0.1.3

type IndexOp int

IndexOp is the operator of a constraint.

const (
	IndexEQ        IndexOp = csqlite.IndexEQ
	IndexGT        IndexOp = csqlite.IndexGT
	IndexLE        IndexOp = csqlite.IndexLE
	IndexLT        IndexOp = csqlite.IndexLT
	IndexGE        IndexOp = csqlite.IndexGE
	IndexMatch     IndexOp = csqlite.IndexMatch
	IndexLike      IndexOp = csqlite.IndexLike
	IndexGlob      IndexOp = csqlite.IndexGlob
	IndexRegexp    IndexOp = csqlite.IndexRegexp
	IndexNE        IndexOp = csqlite.IndexNE
	IndexIsNot     IndexOp = csqlite.IndexIsNot
	IndexIsNotNull IndexOp = csqlite.IndexIsNotNull
	IndexIsNull    IndexOp = csqlite.IndexIsNull
	IndexIs        IndexOp = csqlite.IndexIs
	IndexLimit     IndexOp = csqlite.IndexLimit
	IndexOffset    IndexOp = csqlite.IndexOffset
)

The operators of IndexConstraint.

type IndexOrderBy added in v0.1.3

type IndexOrderBy struct {
	Column int
	Desc   bool
}

IndexOrderBy is a term of the ORDER BY clause.

type IndexUsage added in v0.1.3

type IndexUsage struct {
	ArgvIndex int
	Omit      bool
}

IndexUsage is what BestIndex says of a constraint. ArgvIndex > 0 hands its value to Filter, at args[ArgvIndex-1]: give each used constraint its own number from 1 up. Omit says the scan only gives rows that meet it, so SQLite need not check them again.

type ModuleFlag added in v0.1.3

type ModuleFlag int

ModuleFlag tells SQLite how a module behaves.

const (
	// EponymousOnly: the module is only used by its name, as a function
	// whose arguments are its hidden columns (a table-valued function such
	// as generate_series). CREATE VIRTUAL TABLE with it fails. Without the
	// flag, the module serves only CREATE VIRTUAL TABLE.
	EponymousOnly ModuleFlag = csqlite.ModEponymousOnly
	// ModuleDirectOnly: its tables may be used only by SQL the program
	// runs and by temp triggers and views, never by a trigger or a view
	// stored in a database. Give it to a module that reaches
	// outside the database, such as one that reads files, so that a
	// database file someone else made cannot use it. It cannot go with
	// ModuleInnocuous: a table has one of the two.
	ModuleDirectOnly ModuleFlag = csqlite.ModDirectOnly
	// ModuleInnocuous: the module has no side effects and reveals nothing,
	// so its tables are safe wherever SQL comes from.
	ModuleInnocuous ModuleFlag = csqlite.ModInnocuous
	// ModuleWritable: its tables take INSERT, UPDATE and DELETE when they are
	// VUpdaters. Those statements never merge with others in group commit:
	// the table's own transaction is outside what a merged batch can undo.
	// It cannot go with EponymousOnly.
	ModuleWritable ModuleFlag = csqlite.ModWritable
)

type Option

type Option struct {
	// contains filtered or unexported fields
}

An Option adds something to the connections of a connector: give it to NewConnector, or to Register for the connectors sql.Open makes.

func Join

func Join(opts ...Option) Option

Join makes one Option of several, applied in order: how a package of functions hands them over.

func WithAggregate

func WithAggregate(name string, nArg int, newAggregate func() Aggregate, flags ...FuncFlag) Option

WithAggregate makes an aggregate function name of nArg arguments: for each group, newAggregate makes a state. A group of no rows gets one too, for Final alone.

func WithCollation

func WithCollation(name string, cmp func(a, b string) int) Option

WithCollation makes cmp the collation name, for COLLATE name in queries and in the schema. cmp returns a negative number, 0 or a positive number as a sorts before, with or after b, and must be a total order. It must have no side effects: SQLite calls it as often and in the order its plan needs. A panic in cmp fails the statement with the panic, and SQLite undoes it as it does when memory runs out: it rolls back the statement, or the whole transaction. When the whole transaction is gone, the next statements of it and its Commit fail, and so do the statements merged before it (SQLITE_ABORT_ROLLBACK). The connection stays good.

func WithFunction

func WithFunction(name string, nArg int, fn Func, flags ...FuncFlag) Option

WithFunction makes fn the SQL function name of nArg arguments (-1 for any number) on every connection of the connector. A later option of the same name and nArg replaces an earlier one.

Give a function with no side effects the flag Innocuous. Without it, a write that calls the function is the last of its group commit batch and commits right away, so many writers that call it commit one by one. The same holds for WithAggregate and WithWindow.

Example
//go:build ((linux || darwin) && (amd64 || arm64)) || (windows && (amd64 || arm64))

package main

import (
	"database/sql"
	"database/sql/driver"
	"fmt"
	"strings"

	"github.com/liustack/sqlite"
)

type longest struct{ s string }

func (l *longest) Step(args []driver.Value) error {
	if s, ok := args[0].(string); ok && len(s) > len(l.s) {
		l.s = s
	}
	return nil
}

func (l *longest) Final() (driver.Value, error) { return l.s, nil }

func main() {
	reverse := func(args []driver.Value) (driver.Value, error) {
		s, _ := args[0].(string)
		r := []rune(s)
		for i, j := 0, len(r)-1; i < j; i, j = i+1, j-1 {
			r[i], r[j] = r[j], r[i]
		}
		return string(r), nil
	}
	c, err := sqlite.NewConnector(":memory:",
		sqlite.WithFunction("reverse", 1, reverse, sqlite.Deterministic),
		sqlite.WithAggregate("longest", 1, func() sqlite.Aggregate { return &longest{} }),
		sqlite.WithCollation("nocase_go", func(a, b string) int {
			return strings.Compare(strings.ToLower(a), strings.ToLower(b))
		}))
	if err != nil {
		panic(err)
	}
	db := sql.OpenDB(c)
	defer db.Close()

	var r, l, first string
	err = db.QueryRow(`
		WITH w(word) AS (VALUES ('Banana'), ('apple'), ('cherry'))
		SELECT reverse('stressed'), longest(word),
			(SELECT word FROM w ORDER BY word COLLATE nocase_go LIMIT 1)
		FROM w`).Scan(&r, &l, &first)
	if err != nil {
		panic(err)
	}
	fmt.Println(r, l, first)
}
Output:
desserts Banana apple

func WithModule added in v0.1.3

func WithModule(name string, connect func(args []string) (VTable, error), flags ...ModuleFlag) Option

WithModule makes a virtual table module name on every connection of the connector. connect makes a table for CREATE VIRTUAL TABLE t USING name(args...), and when a connection first uses such a table, or, for an EponymousOnly module, for its name used as a table, with no args. args are the arguments as SQL wrote them, without quotes taken off. A later option of the same name replaces an earlier one.

func WithWindow added in v0.1.3

func WithWindow(name string, nArg int, newWindow func() Window, flags ...FuncFlag) Option

WithWindow makes an aggregate window function name of nArg arguments, which also works as an aggregate without OVER: for each partition or group, newWindow makes a state.

type VCursor added in v0.1.3

type VCursor interface {
	// Filter starts the scan with the plan BestIndex chose: idxNum and
	// idxStr as it set them, and args the values of the constraints it gave
	// an ArgvIndex, args[ArgvIndex-1] for each. The values are copies, as
	// a Func gets them. Filter may run again on the same cursor, to start
	// over.
	Filter(idxNum int, idxStr string, args []driver.Value) error
	// Next goes to the next row.
	Next() error
	// EOF says the scan is past its last row. It runs after Filter and
	// after each Next.
	EOF() bool
	// Column is column i of the row, a value as a Func returns.
	Column(i int) (driver.Value, error)
	// RowID is the rowid of the row.
	RowID() (int64, error)
	Close() error
}

VCursor is a scan of a VTable.

type VSavepointer added in v0.1.3

type VSavepointer interface {
	Savepoint(n int) error
	Release(n int) error
	RollbackTo(n int) error
}

VSavepointer is a VTransactor that keeps savepoints, so that a statement that fails inside a transaction is undone in the table too: Savepoint(n) marks the state, RollbackTo(n) goes back to the state at savepoint n, and Release(n) forgets the marks from n on. A table that joined the transaction after savepoint n was opened has no mark for it: RollbackTo(n) then goes back to the state at Begin.

type VTable added in v0.1.3

type VTable interface {
	// Schema is the CREATE TABLE statement of its columns, such as
	// "CREATE TABLE x(value, start HIDDEN)". The name of the table in it
	// is not used. A HIDDEN column is not in SELECT *, and when the module
	// is used by its name as a function, its arguments give the hidden
	// columns, in order: they reach BestIndex as constraints of EQ.
	Schema() string
	// BestIndex chooses how to scan the table under the constraints of
	// info, and says what the scan costs. SQLite may ask several times
	// with different constraints and runs the cheapest. It returns
	// ErrUnusablePlan when the scan cannot work with the constraints that
	// are usable, such as when an argument it needs is missing.
	BestIndex(info *IndexInfo) error
	// Open makes a cursor for a scan.
	Open() (VCursor, error)
	// Disconnect ends the table on its connection.
	Disconnect() error
}

VTable is a table of a virtual table module, written in Go, on one connection. It only reads, unless its module is ModuleWritable and it is also a VUpdater.

Each connection connects a table of its own, and uses it from one goroutine at a time. Something the tables of several connections share is used from several goroutines at once. Like a Func, a table must not use the database. A statement that reads a table never merges with others in group commit, so it always reads the table of its own connection.

type VTransactor added in v0.1.3

type VTransactor interface {
	Begin() error
	Sync() error
	Commit() error
	Rollback() error
}

VTransactor is a VUpdater that takes part in the transactions of its connection. Begin runs before the first write of the table in a transaction, and as CREATE VIRTUAL TABLE makes the table. Sync, then Commit, run at the commit, or Rollback at the rollback. A failed Sync fails the commit. Commit runs after the database committed, so its error is lost: write what must last in Sync. Without VTransactor, a statement that fails leaves what it wrote to the table.

type VUpdater added in v0.1.3

type VUpdater interface {
	// Insert adds a row of the values cols. rowid is nil when the
	// statement gave none, and Insert chooses one. It returns the rowid of
	// the row, which last_insert_rowid() and LastInsertId give. In a table
	// declared WITHOUT ROWID, rowid is always nil, the key is in cols, and
	// the number returned only goes to last_insert_rowid().
	Insert(rowid driver.Value, cols []driver.Value) (int64, error)
	// Update changes the row oldRowid to newRowid and cols.
	Update(oldRowid, newRowid driver.Value, cols []driver.Value) error
	Delete(rowid driver.Value) error
}

VUpdater is a VTable that takes INSERT, UPDATE and DELETE, of a module made with ModuleWritable. A rowid is an int64, or in a table declared WITHOUT ROWID the value of its PRIMARY KEY. Column values come as a Func's arguments. The table does not learn the statement's ON CONFLICT clause: an error fails the statement, also in INSERT OR IGNORE.

type Window added in v0.1.3

type Window interface {
	Aggregate
	Value() (driver.Value, error)
	Inverse(args []driver.Value) error
}

Window is the state of one partition of an aggregate window function written in Go, used with OVER. As the frame moves, Step adds a row that came into it and Inverse takes out a row that left it, with the arguments Step had for that row. Value gives the result for the rows in the frame, and may be asked when the frame has no rows. Final runs once at the end of the partition, and gives the result when the function is used without OVER.

Directories

Path Synopsis
ext
csv
Package csv gives SQLite the csv virtual table of SQLite's csv extension (ext/misc/csv.c), ported to Go:
Package csv gives SQLite the csv virtual table of SQLite's csv extension (ext/misc/csv.c), ported to Go:
hash
Package hash gives SQLite hash functions:
Package hash gives SQLite hash functions:
internal/arg
Package arg reads the arguments of the functions of ext/.
Package arg reads the arguments of the functions of ext/.
internal/sqltest
Package sqltest runs the queries of the tests of ext/.
Package sqltest runs the queries of the tests of ext/.
regexp
Package regexp gives SQLite the REGEXP operator and regexp functions, with Go's regexp syntax (RE2: no backreferences, and time linear in the text).
Package regexp gives SQLite the REGEXP operator and regexp functions, with Go's regexp syntax (RE2: no backreferences, and time linear in the text).
series
Package series gives SQLite generate_series, the table-valued function of SQLite's series extension (ext/misc/series.c), ported to Go:
Package series gives SQLite generate_series, the table-valued function of SQLite's series extension (ext/misc/series.c), ported to Go:
stats
Package stats gives SQLite the variance and the standard deviation as aggregate functions:
Package stats gives SQLite the variance and the standard deviation as aggregate functions:
unicode
Package unicode gives SQLite case rules for every script, where SQLite's own upper, lower and NOCASE know only ASCII:
Package unicode gives SQLite case rules for every script, where SQLite's own upper, lower and NOCASE know only ASCII:
uuid
Package uuid gives SQLite the functions of SQLite's own uuid extension:
Package uuid gives SQLite the functions of SQLite's own uuid extension:
vec
Package vec gives SQLite vector functions, for similarity search over vectors kept in ordinary tables:
Package vec gives SQLite vector functions, for similarity search over vectors kept in ordinary tables:
internal
extapi
Package extapi gives the packages of ext/ what the driver does not offer its users.
Package extapi gives the packages of ext/ what the driver does not offer its users.
goversion
Package goversion stops a build with a Go newer than the one the engine was checked with.
Package goversion stops a build with a Go newer than the one the engine was checked with.
powerloss
Package powerloss builds the files a power loss could leave in a directory, for the tests that play one.
Package powerloss builds the files a power loss could leave in a directory, for the tests that play one.
queuehook
Package queuehook gives the queue (package queue) what it needs of the driver and the driver does not offer its users.
Package queuehook gives the queue (package queue) what it needs of the driver and the driver does not offer its users.
replhook
Package replhook gives the replicator (replica/internal/capture) what it needs of the driver and the driver does not offer its users.
Package replhook gives the replicator (replica/internal/capture) what it needs of the driver and the driver does not offer its users.
vfs
Package vfs is the operating system layer of SQLite, in Go: the files, locks and shared memory that os_unix.c gives a normal build.
Package vfs is the operating system layer of SQLite, in Go: the files, locks and shared memory that os_unix.c gives a normal build.
Package queue is a queue of messages kept in a SQLite database opened with github.com/liustack/sqlite: a channel that does not lose what was sent.
Package queue is a queue of messages kept in a SQLite database opened with github.com/liustack/sqlite: a channel that does not lose what was sent.
Package replica copies a database of the driver to S3 (AWS S3, Cloudflare R2, MinIO and the other stores that speak its API) as it changes, so that it can be restored after the machine is lost.
Package replica copies a database of the driver to S3 (AWS S3, Cloudflare R2, MinIO and the other stores that speak its API) as it changes, so that it can be restored after the machine is lost.
internal/capture
Package capture copies each change of a database in WAL mode into LTX files in a local staging folder, from which the replicator uploads them, and runs the database's checkpoints, so that no frame is checkpointed before it is copied.
Package capture copies each change of a database in WAL mode into LTX files in a local staging folder, from which the replicator uploads them, and runs the database's checkpoints, so that no frame is checkpointed before it is copied.
internal/s3
Package s3 is the small client of the S3 protocol the replicator uses: PUT, multipart upload, ranged GET, ListObjectsV2 and DELETE, signed with SigV4, against AWS S3 and the stores that speak its protocol (Cloudflare R2, MinIO and the like).
Package s3 is the small client of the S3 protocol the replicator uses: PUT, multipart upload, ranged GET, ListObjectsV2 and DELETE, signed with SigV4, against AWS S3 and the stores that speak its protocol (Cloudflare R2, MinIO and the like).
internal/s3test
Package s3test gives tests an S3 store:
Package s3test gives tests an S3 store:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL