mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 06:12:45 +00:00
Merge Updater structs (#1069)
* Move Updater structs to shared and use it for postgres * Add constructors for NewXXXUpdater and a useTxns flag In sqlite, we set useTxns=false and comment why. * Handle nil txn * Handle nil in transaction * Missed one * Close the txn at the right time * Don't close the transaction as we reuse it between calls
This commit is contained in:
parent
02fe38e1f7
commit
a6f995eb45
8 changed files with 381 additions and 744 deletions
|
@ -16,6 +16,7 @@
|
|||
package shared
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
|
@ -34,3 +35,26 @@ func (s StatementList) Prepare(db *sql.DB) (err error) {
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
type transaction struct {
|
||||
ctx context.Context
|
||||
txn *sql.Tx
|
||||
}
|
||||
|
||||
// Commit implements types.Transaction
|
||||
func (t *transaction) Commit() error {
|
||||
if t.txn == nil {
|
||||
// The Updater structs can operate in useTxns=false mode. The code will still call this though.
|
||||
return nil
|
||||
}
|
||||
return t.txn.Commit()
|
||||
}
|
||||
|
||||
// Rollback implements types.Transaction
|
||||
func (t *transaction) Rollback() error {
|
||||
if t.txn == nil {
|
||||
// The Updater structs can operate in useTxns=false mode. The code will still call this though.
|
||||
return nil
|
||||
}
|
||||
return t.txn.Rollback()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue