errorFilter: err => {
const willRetry = (err.name === 'SequelizeDatabaseError')
- logger.debug('Maybe retrying the transaction function.', { willRetry, err })
+ logger.debug('Maybe retrying the transaction function.', { willRetry, err, tags: [ 'sql', 'retry' ] })
return willRetry
}
},
})
}
+// ---------------------------------------------------------------------------
+
function updateInstanceWithAnother <M, T extends U, U extends Model<M>> (instanceToUpdate: T, baseInstance: U) {
const obj = baseInstance.toJSON()
})
}
-function afterCommitIfTransaction (t: Transaction, fn: Function) {
- if (t) return t.afterCommit(() => fn())
-
- return fn()
-}
-
function deleteNonExistingModels <T extends { hasSameUniqueKeysThan (other: T): boolean } & Pick<Model, 'destroy'>> (
fromDatabase: T[],
newModels: T[],
// ---------------------------------------------------------------------------
+function runInReadCommittedTransaction <T> (fn: (t: Transaction) => Promise<T>) {
+ const options = { isolationLevel: Transaction.ISOLATION_LEVELS.READ_COMMITTED }
+
+ return sequelizeTypescript.transaction(options, t => fn(t))
+}
+
+function afterCommitIfTransaction (t: Transaction, fn: Function) {
+ if (t) return t.afterCommit(() => fn())
+
+ return fn()
+}
+
+// ---------------------------------------------------------------------------
+
export {
resetSequelizeInstance,
retryTransactionWrapper,
updateInstanceWithAnother,
afterCommitIfTransaction,
deleteNonExistingModels,
- setAsUpdated
+ setAsUpdated,
+ runInReadCommittedTransaction
}