Documentation
¶
Overview ¶
Package sqlite reads another program's SQLite database without touching it: Open copies the database and its write-ahead log into a private temporary directory and opens the copy, which SQLite recovers as a crashed writer's, so every frame the log holds up to its last commit is read, checkpointed or not. A database is never opened in place, since SQLite creates a -wal and a -shm file beside a database in WAL mode even for a read-only connection, and a connection that closes last may checkpoint. The program that owns the database may keep writing while it is copied, so the copy is checked: the database file and the log's header must be the same after the copy as before it, else the copy is retried a few times and then refused with ErrBusy.
It imports modernc.org/sqlite, a SQLite written in Go, and is one of the packages scripts/check-deps.sh lets do so, its path ending in /sqlite; the format packages' sqlite packages build on it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBusy = errors.New("the database kept changing while it was copied; the program writing it may be running, try again when it is idle")
ErrBusy is returned by Open when the database kept changing while it was copied: the program that owns it is writing to it.
Functions ¶
func Fixture ¶
Fixture builds a database at path from SQL text, for tests: the fixtures of this module are SQL text, never database files. The database is put in WAL mode with automatic checkpoints off and returned open: rows the script writes stay in the write-ahead log, where a reader finds them only through the log, for as long as the returned closer is not closed. Closing it checkpoints the log into the database.
func IsDatabase ¶
IsDatabase reports whether the file at path starts with SQLite's header.
func RemoveCopies ¶
func RemoveCopies()
RemoveCopies removes the copy of every database open: what a program interrupted while it reads one calls before it exits, as a deferred Close does not run then. The copies are in os.TempDir, under $TMPDIR when it is set.
Types ¶
type Copy ¶
Copy is a copy of a database, open for reading. It is not safe for concurrent use.
func Open ¶
Open copies the database at path into a temporary directory whose name starts with prefix, and opens the copy. Close removes it.