Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database: Document context limitations of Tx.Commit() #73

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,11 @@ func (db *DB) NamedBulkExec(
// Takes in up to the number of entities specified in count from the arg stream and
// executes a new transaction that runs a new query for each entity in this set of arguments,
// until the arg stream has been processed.
//
// The transactions are executed in a separate goroutine with a weighting of 1
// and can be executed concurrently to the extent allowed by the semaphore passed in sem.
//
// Note that committing the transaction may not honor the context provided, as described further in [DB.ExecTx].
func (db *DB) NamedBulkExecTx(
ctx context.Context, query string, count int, sem *semaphore.Weighted, arg <-chan Entity,
) error {
Expand Down Expand Up @@ -776,6 +779,10 @@ func (db *DB) Delete(
// if the function succeeds. If the function returns an error, the transaction is rolled back.
//
// Returns an error if starting the transaction, executing the function, or committing the transaction fails.
//
// Note that committing the transaction may not honor the context provided. For some database drivers, once a COMMIT
// query is started, it will block until the database responds. Therefore, for time-critical scenarios, it is
// recommended to add a select wrapper against the context.
func (db *DB) ExecTx(ctx context.Context, fn func(context.Context, *sqlx.Tx) error) error {
tx, err := db.BeginTxx(ctx, nil)
if err != nil {
Expand Down
Loading