File tree Expand file tree Collapse file tree 4 files changed +41
-2
lines changed Expand file tree Collapse file tree 4 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -6,4 +6,7 @@ SQLite VFS in pure Go.
66It has some benefits over the C version:
77- the memory backing the database needs not be contiguous,
88- the database can grow/shrink incrementally without copying,
9- - reader-writer concurrency is slightly improved.
9+ - reader-writer concurrency is slightly improved.
10+
11+ [ ` memdb.TestDB ` ] ( https://pkg.go.dev/github.com/ncruces/go-sqlite3/vfs/memdb#TestDB )
12+ is the preferred way to setup an in-memory database for testing.
Original file line number Diff line number Diff line change @@ -77,6 +77,21 @@ func Delete(name string) {
7777// The database is automatically deleted when the test and all its subtests complete.
7878// Returns a URI filename appropriate to call Open with.
7979// Each subsequent call to TestDB returns a unique database.
80+ //
81+ // func Test_something(t *testing.T) {
82+ // t.Parallel()
83+ // dsn := memdb.TestDB(t, url.Values{
84+ // "_pragma": {"busy_timeout(1000)"},
85+ // })
86+ //
87+ // db, err := sql.Open("sqlite3", dsn)
88+ // if err != nil {
89+ // t.Fatal(err)
90+ // }
91+ // defer db.Close()
92+ //
93+ // // ...
94+ // }
8095func TestDB (tb testing.TB , params ... url.Values ) string {
8196 tb .Helper ()
8297
Original file line number Diff line number Diff line change @@ -6,4 +6,10 @@ It has some benefits over the [`"memdb"`](../memdb/README.md) VFS:
66- panics do not corrupt a shared database,
77- single-writer not blocked by readers,
88- readers never block,
9- - instant snapshots.
9+ - instant snapshots.
10+
11+ [ ` mvcc.TestDB ` ] ( https://pkg.go.dev/github.com/ncruces/go-sqlite3/vfs/mvcc#TestDB )
12+ is the preferred way to setup an in-memory database for testing
13+ when you intend to leverage snapshots,
14+ e.g. to setup many independent copies of a database,
15+ such as one for each subtest.
Original file line number Diff line number Diff line change @@ -98,6 +98,21 @@ func TakeSnapshot(name string) Snapshot {
9898// The database is automatically deleted when the test and all its subtests complete.
9999// Returns a URI filename appropriate to call Open with.
100100// Each subsequent call to TestDB returns a unique database.
101+ //
102+ // func Test_something(t *testing.T) {
103+ // t.Parallel()
104+ // dsn := mvcc.TestDB(t, snapshot, url.Values{
105+ // "_pragma": {"busy_timeout(1000)"},
106+ // })
107+ //
108+ // db, err := sql.Open("sqlite3", dsn)
109+ // if err != nil {
110+ // t.Fatal(err)
111+ // }
112+ // defer db.Close()
113+ //
114+ // // ...
115+ // }
101116func TestDB (tb testing.TB , snapshot Snapshot , params ... url.Values ) string {
102117 tb .Helper ()
103118
You can’t perform that action at this time.
0 commit comments