mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-27 08:15:39 +02:00
[#1291] added condition to switch between the db pools in case of dry submit
This commit is contained in:
parent
7d7d20744e
commit
a43713ce14
@ -675,9 +675,16 @@ func (form *RecordUpsert) DrySubmit(callback func(txDao *daos.Dao) error) error
|
||||
return err
|
||||
}
|
||||
|
||||
// use the default app.Dao().ConcurrentDB() to prevent changing the transaction form.Dao
|
||||
// and causing "transaction has already been committed or rolled back" error
|
||||
dryDao := daos.New(form.app.Dao().ConcurrentDB())
|
||||
var dryDao *daos.Dao
|
||||
if form.dao.ConcurrentDB() == form.dao.NonconcurrentDB() {
|
||||
// it is already in a transaction and therefore use the app concurrent db pool
|
||||
// to prevent "transaction has already been committed or rolled back" error
|
||||
dryDao = daos.New(form.app.Dao().ConcurrentDB())
|
||||
} else {
|
||||
// otherwise use the form noncurrent dao db pool
|
||||
dryDao = daos.New(form.dao.NonconcurrentDB())
|
||||
}
|
||||
|
||||
return dryDao.RunInTransaction(func(txDao *daos.Dao) error {
|
||||
tx, ok := txDao.DB().(*dbx.Tx)
|
||||
if !ok {
|
||||
@ -685,11 +692,6 @@ func (form *RecordUpsert) DrySubmit(callback func(txDao *daos.Dao) error) error
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
txDao.BeforeCreateFunc = nil
|
||||
txDao.AfterCreateFunc = nil
|
||||
txDao.BeforeUpdateFunc = nil
|
||||
txDao.AfterUpdateFunc = nil
|
||||
|
||||
if err := txDao.SaveRecord(form.record); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user