Documentation ¶
Overview ¶
Package memdb implements the "memdb" SQLite VFS.
The "memdb" 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 memdb registers the VFS:
import _ "github.com/ncruces/go-sqlite3/vfs/memdb"
Example ¶
package main import ( "database/sql" "fmt" "log" _ "embed" _ "github.com/ncruces/go-sqlite3/driver" _ "github.com/ncruces/go-sqlite3/embed" "github.com/ncruces/go-sqlite3/vfs/memdb" ) //go:embed testdata/test.db var testDB []byte func main() { memdb.Create("test.db", testDB) db, err := sql.Open("sqlite3", "file:/test.db?vfs=memdb") 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 ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.