Documentation
¶
Overview ¶
Package mvcc implements the "mvcc" SQLite VFS.
The "mvcc" vfs.VFS allows the same in-memory database to be shared among multiple database connections in the same process, as long as the database name begins with "/".
Importing package mvcc registers the VFS:
import _ "github.com/ncruces/go-sqlite3/vfs/mvcc"
Example ¶
package main import ( "database/sql" _ "embed" "fmt" "log" _ "github.com/ncruces/go-sqlite3/driver" _ "github.com/ncruces/go-sqlite3/embed" "github.com/ncruces/go-sqlite3/vfs/mvcc" ) //go:embed testdata/test.db var testDB string func main() { mvcc.Create("test.db", mvcc.NewSnapshot(testDB)) db, err := sql.Open("sqlite3", "file:/test.db?vfs=mvcc") if err != nil { log.Fatal(err) } defer db.Close() _, err = db.Exec(`INSERT INTO users (id, name) VALUES (3, 'rust')`) if err != nil { log.Fatal(err) } rows, err := db.Query(`SELECT id, name FROM users`) if err != nil { log.Fatal(err) } defer rows.Close() for rows.Next() { var id, name string err = rows.Scan(&id, &name) if err != nil { log.Fatal(err) } fmt.Printf("%s %s\n", id, name) } }
Output: 0 go 1 zig 2 whatever 3 rust
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TestDB ¶ added in v0.29.1
TestDB creates a shared database from a snapshot for the test to use. The database is automatically deleted when the test and all its subtests complete. Returns a URI filename appropriate to call Open with. Each subsequent call to TestDB returns a unique database.
func Test_something(t *testing.T) { t.Parallel() dsn := mvcc.TestDB(t, snapshot, url.Values{ "_pragma": {"busy_timeout(1000)"}, }) db, err := sql.Open("sqlite3", dsn) if err != nil { t.Fatal(err) } defer db.Close() // ... }
Types ¶
type Snapshot ¶
Snapshot represents a database snapshot.
func NewSnapshot ¶ added in v0.29.1
NewSnapshot creates a snapshot from data.
func TakeSnapshot ¶ added in v0.29.1
TakeSnapshot takes a snapshot of a database. Name may be a URI filename.