Skip to content

Commit ea860e4

Browse files
committed
Docs.
1 parent d4561d0 commit ea860e4

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

vfs/memdb/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ SQLite VFS in pure Go.
66
It 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.

vfs/memdb/api.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
// }
8095
func TestDB(tb testing.TB, params ...url.Values) string {
8196
tb.Helper()
8297

vfs/mvcc/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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.

vfs/mvcc/api.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
// }
101116
func TestDB(tb testing.TB, snapshot Snapshot, params ...url.Values) string {
102117
tb.Helper()
103118

0 commit comments

Comments
 (0)