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 ¶
type MemDB ¶
type MemDB struct {
// contains filtered or unexported fields
}
MemDB is a no-export memDB struct dump helper. Note: This struct does not provide concurrency safety, and you must manage concurrent access yourself.
func Create ¶
Create creates a shared memory database, using data as its initial contents. The new database takes ownership of data, and the caller should not use data after this call.
func (*MemDB) Dump ¶ added in v1.0.2
func (m *MemDB) Dump() io.ReadSeekCloser
type MemDBDumper ¶ added in v1.0.2
type MemDBDumper struct {
// contains filtered or unexported fields
}
func (*MemDBDumper) Close ¶ added in v1.0.2
func (m *MemDBDumper) Close() error
Click to show internal directories.
Click to hide internal directories.