Skip to content

Commit 6189f9b

Browse files
committed
Replace inline doc examples with proper godoc examples
1 parent 886ef73 commit 6189f9b

File tree

5 files changed

+35
-31
lines changed

5 files changed

+35
-31
lines changed

example_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"io"
1111
"regexp"
12+
"time"
1213

1314
"zombiezen.com/go/sqlite"
1415
"zombiezen.com/go/sqlite/sqlitex"
@@ -77,7 +78,8 @@ func ExampleConn_SetInterrupt() {
7778

7879
// You can use the Done() channel from a context to set deadlines and timeouts
7980
// on queries.
80-
ctx := context.TODO()
81+
ctx, cancel := context.WithTimeout(context.TODO(), 100*time.Millisecond)
82+
defer cancel()
8183
conn.SetInterrupt(ctx.Done())
8284
}
8385

sqlite.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,6 @@ func (c *Conn) CheckReset() string {
250250
// Subsequent uses of the connection will return SQLITE_INTERRUPT
251251
// errors until doneCh is reset with a subsequent call to SetInterrupt.
252252
//
253-
// Typically, doneCh is provided by the Done method on a context.Context.
254-
// For example, a timeout can be associated with a connection session:
255-
//
256-
// ctx := context.WithTimeout(context.Background(), 100*time.Millisecond)
257-
// conn.SetInterrupt(ctx.Done())
258-
//
259253
// Any busy statements at the time SetInterrupt is called will be reset.
260254
//
261255
// SetInterrupt returns the old doneCh assigned to the connection.

sqlitex/example_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package sqlitex_test
55

66
import (
7+
"context"
78
"fmt"
89

910
"zombiezen.com/go/sqlite"
@@ -45,3 +46,34 @@ func ExampleExecute() {
4546
// Output:
4647
// [a1] [1]
4748
}
49+
50+
func ExampleSave() {
51+
doWork := func(conn *sqlite.Conn) (err error) {
52+
defer sqlitex.Save(conn)(&err)
53+
54+
// ... do work in the transaction
55+
return nil
56+
}
57+
_ = doWork
58+
}
59+
60+
func ExamplePool() {
61+
// Open a pool.
62+
dbpool, err := sqlitex.Open("foo.db", 0, 10)
63+
if err != nil {
64+
// handle err
65+
}
66+
defer func() {
67+
if err := dbpool.Close(); err != nil {
68+
// handle err
69+
}
70+
}()
71+
72+
// While handling a request:
73+
ctx := context.TODO()
74+
conn := dbpool.Get(ctx)
75+
if conn == nil {
76+
// handle err
77+
}
78+
defer dbpool.Put(conn)
79+
}

sqlitex/pool.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,7 @@ import (
2626
)
2727

2828
// Pool is a pool of SQLite connections.
29-
//
3029
// It is safe for use by multiple goroutines concurrently.
31-
//
32-
// Typically, a goroutine that needs to use an SQLite *Conn
33-
// Gets it from the pool and defers its return:
34-
//
35-
// conn := dbpool.Get(nil)
36-
// defer dbpool.Put(conn)
37-
//
38-
// As Get may block, a context can be used to return if a task
39-
// is cancelled. In this case the Conn returned will be nil:
40-
//
41-
// conn := dbpool.Get(ctx)
42-
// if conn == nil {
43-
// return context.Canceled
44-
// }
45-
// defer dbpool.Put(conn)
4630
type Pool struct {
4731
free chan *sqlite.Conn
4832
closed chan struct{}

sqlitex/savepoint.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ import (
3131
// RELEASE or ROLLBACK depending on whether the parameter *error
3232
// points to a nil or non-nil error. This is designed to be deferred.
3333
//
34-
// Example:
35-
//
36-
// func doWork(conn *sqlite.Conn) (err error) {
37-
// defer sqlitex.Save(conn)(&err)
38-
//
39-
// // ... do work in the transaction
40-
// }
41-
//
4234
// https://www.sqlite.org/lang_savepoint.html
4335
func Save(conn *sqlite.Conn) (releaseFn func(*error)) {
4436
name := "sqlitex.Save" // safe as names can be reused

0 commit comments

Comments
 (0)