SQLite3 driver interface for Go
Switch branches/tags
Nothing to show
Clone or download
crawshaw sqlite: disable shared cache by default
The shared cache works well but is probably not the right default.
It has much stricter locking semantics than you get from SQLite
with a WAL database, reducing performance in some important cases.

This appears to be an implementation limit of the shared cache,
not something fundamental to its design. If it ever gets WAL-like
locking it should be turned on by default.
Latest commit c225a6c Sep 19, 2018
Permalink
Failed to load latest commit information.
sqliteutil sqlite: make sure Step always resets on error Sep 18, 2018
.travis.yml Add simple travis config, closes #22 Jun 30, 2018
LICENSE initial commit Mar 29, 2018
README.md Fix typo in example code (handle -> handler) (#37) Aug 17, 2018
appveyor.yml Add tentative appveyor config Jun 30, 2018
blob.go sqlite: blob Read/Write/Seek and multiple Close May 10, 2018
blob_test.go sqlite: disable shared cache by default Sep 19, 2018
blocking_step.c initial implementation Mar 29, 2018
blocking_step.h initial implementation Mar 29, 2018
doc.go sqlite: add package docs Mar 30, 2018
error.go Handle wrapped errors, closes #28 Jun 30, 2018
export_test.go sqlite: handle SQLITE_INTERRUPT in Prep Apr 1, 2018
extension.go Enable the load extension API (#39) Aug 25, 2018
extension_test.go sqlite: fix test format string Sep 18, 2018
func.go sqlite: fix types and flags for OpenBSD Apr 19, 2018
func_test.go sqlite: add custom function support Mar 31, 2018
pool.go sqlite: disable shared cache by default Sep 19, 2018
pool_test.go sqlite: disable shared cache by default Sep 19, 2018
session.go sqlite: blob Read/Write/Seek and multiple Close May 10, 2018
session_test.go sqlite: check for conflict in patchset test Sep 18, 2018
sqlite.go sqlite: disable shared cache by default Sep 19, 2018
sqlite3.c sqlite: upgrade to SQLite 3.25.1 Sep 19, 2018
sqlite3.h sqlite: upgrade to SQLite 3.25.1 Sep 19, 2018
sqlite3ext.h sqlite: upgrade to SQLite 3.25.1 Sep 19, 2018
sqlite_test.go sqlite: add SetBusyTimeout Sep 19, 2018

README.md

Go interface to SQLite.

GoDoc Build Status (linux and macOS) Build status (windows)

This package provides a low-level Go interface to SQLite 3 designed to take maximum advantage of multi-threading. Connections are pooled and take advantage of the SQLite shared cache mode and the package takes advantage of the unlock-notify API to minimize the amount of handling user code needs for dealing with database lock contention.

It has interfaces for some of SQLite's more interesting extensions, such as incremental BLOB I/O and the session extension.

A utility package, sqliteutil, provides some higher-level tools for making it easier to perform common tasks with SQLite. In particular it provides support to make nested transactions easy to use via sqliteutil.Save.

This is not a database/sql driver.

go get -u crawshaw.io/sqlite

Example

A HTTP handler that uses a multi-threaded pool of SQLite connections via a shared cache.

var dbpool *sqlite.Pool

func main() {
	var err error
	dbpool, err = sqlite.Open("file:memory:?mode=memory", 0, 10)
	if err != nil {
		log.Fatal(err)
	}
	http.Handle("/", handler)
	log.Fatal(http.ListenAndServe(":8080", nil))
}

func handler(w http.ResponseWriter, r *http.Request) {
	conn := dbpool.Get(r.Context().Done())
	if conn == nil {
		return
	}
	defer dbpool.Put(conn)
	stmt := conn.Prep("SELECT foo FROM footable WHERE id = $id;")
	stmt.SetText("$id", "_user_id_")
	for {
		if hasRow, err := stmt.Step(); err != nil {
			// ... handle error
		} else if !hasRow {
			break
		}
		foo := stmt.GetText("foo")
		// ... use foo
	}
}

https://godoc.org/crawshaw.io/sqlite