MCPcopy
hub / github.com/pocketbase/pocketbase / runInTransaction

Method runInTransaction

core/db_tx.go:25–49  ·  view source on GitHub ↗
(db dbx.Builder, fn func(txApp App) error, isForAuxDB bool)

Source from the content-addressed store, hash-verified

23}
24
25func (app *BaseApp) runInTransaction(db dbx.Builder, fn func(txApp App) error, isForAuxDB bool) error {
26 switch txOrDB := db.(type) {
27 case *dbx.Tx:
28 // run as part of the already existing transaction
29 return fn(app)
30 case *dbx.DB:
31 var txApp *BaseApp
32 txErr := txOrDB.Transactional(func(tx *dbx.Tx) error {
33 txApp = app.createTxApp(tx, isForAuxDB)
34 return fn(txApp)
35 })
36
37 // execute all after event calls on transaction complete
38 if txApp != nil && txApp.txInfo != nil {
39 afterFuncErr := txApp.txInfo.runAfterFuncs(txErr)
40 if afterFuncErr != nil {
41 return errors.Join(txErr, afterFuncErr)
42 }
43 }
44
45 return txErr
46 default:
47 return errors.New("failed to start transaction (unknown db type)")
48 }
49}
50
51// createTxApp shallow clones the current app and assigns a new tx state.
52func (app *BaseApp) createTxApp(tx *dbx.Tx, isForAuxDB bool) *BaseApp {

Callers 2

RunInTransactionMethod · 0.95
AuxRunInTransactionMethod · 0.95

Calls 3

createTxAppMethod · 0.95
runAfterFuncsMethod · 0.80
fnFunction · 0.50

Tested by

no test coverage detected