Skip to content

Commit 55dba87

Browse files
authored
database/sql: document Stmt lifetime
1 parent 1fb5961 commit 55dba87

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/database/sql/sql.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,6 +2256,13 @@ var (
22562256

22572257
// Stmt is a prepared statement.
22582258
// A Stmt is safe for concurrent use by multiple goroutines.
2259+
//
2260+
// If a Stmt is prepared on a Tx or Conn, it will be bound to a single
2261+
// underlying connection forever. If the Tx or Conn closes, the Stmt will
2262+
// become unusable and all operations will return an error.
2263+
// If a Stmt is prepared on a DB, it will remain usable for the lifetime of the
2264+
// DB. When the Stmt needs to execute on a new underlying connection, it will
2265+
// prepare itself on the new connection automatically.
22592266
type Stmt struct {
22602267
// Immutable:
22612268
db *DB // where we came from

0 commit comments

Comments
 (0)