Skip to content

Commit 990af03

Browse files
blmhemuzombiezen
andauthored
Add Pool.Take method in sqlitemigration (#97)
Co-authored-by: Ross Light <[email protected]>
1 parent 1cb3c37 commit 990af03

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Added
1313

14+
- `sqlitemigration.Pool` now has a new method `Take`
15+
so that it implements a common interface with `sqlitex.Pool`
16+
([#97](https://github.com/zombiezen/go-sqlite/pull/97)).
1417
- Documented `OpenWAL` behavior on `sqlite.OpenConn`.
1518

1619
### Fixed

Diff for: sqlitemigration/sqlitemigration.go

+35-1
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,42 @@ func (p *Pool) Close() error {
130130
return p.pool.Close()
131131
}
132132

133-
// Get gets an SQLite connection from the pool.
133+
// Get obtains an SQLite connection from the pool,
134+
// waiting until the initial migration is complete.
135+
// Get is identical to [Pool.Take].
136+
//
137+
// If no connection is available,
138+
// Get will block until at least one connection is returned with [Pool.Put],
139+
// or until either the Pool is closed or the context is canceled.
140+
// If no connection can be obtained
141+
// or an error occurs while preparing the connection,
142+
// an error is returned.
143+
//
144+
// The provided context is also used to control the execution lifetime of the connection.
145+
// See [sqlite.Conn.SetInterrupt] for details.
146+
//
147+
// Applications must ensure that all non-nil Conns returned from Get
148+
// are returned to the same Pool with [Pool.Put].
134149
func (p *Pool) Get(ctx context.Context) (*sqlite.Conn, error) {
150+
return p.Take(ctx)
151+
}
152+
153+
// Take obtains an SQLite connection from the pool,
154+
// waiting until the initial migration is complete.
155+
//
156+
// If no connection is available,
157+
// Take will block until at least one connection is returned with [Pool.Put],
158+
// or until either the Pool is closed or the context is canceled.
159+
// If no connection can be obtained
160+
// or an error occurs while preparing the connection,
161+
// an error is returned.
162+
//
163+
// The provided context is also used to control the execution lifetime of the connection.
164+
// See [sqlite.Conn.SetInterrupt] for details.
165+
//
166+
// Applications must ensure that all non-nil Conns returned from Take
167+
// are returned to the same Pool with [Pool.Put].
168+
func (p *Pool) Take(ctx context.Context) (*sqlite.Conn, error) {
135169
tick := time.NewTicker(5 * time.Second)
136170
for ready := false; !ready; {
137171
// Inform Pool.open to keep trying.

0 commit comments

Comments
 (0)