aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/database-utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/database-utils.ts')
-rw-r--r--server/helpers/database-utils.ts10
1 files changed, 9 insertions, 1 deletions
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts
index 39c74b2fd..6c5068fb0 100644
--- a/server/helpers/database-utils.ts
+++ b/server/helpers/database-utils.ts
@@ -2,6 +2,7 @@ import * as retry from 'async/retry'
2import * as Bluebird from 'bluebird' 2import * as Bluebird from 'bluebird'
3import { Model } from 'sequelize-typescript' 3import { Model } from 'sequelize-typescript'
4import { logger } from './logger' 4import { logger } from './logger'
5import { Transaction } from 'sequelize'
5 6
6function retryTransactionWrapper <T, A, B, C> ( 7function retryTransactionWrapper <T, A, B, C> (
7 functionToRetry: (arg1: A, arg2: B, arg3: C) => Promise<T> | Bluebird<T>, 8 functionToRetry: (arg1: A, arg2: B, arg3: C) => Promise<T> | Bluebird<T>,
@@ -72,11 +73,18 @@ function resetSequelizeInstance (instance: Model<any>, savedFields: object) {
72 }) 73 })
73} 74}
74 75
76function afterCommitIfTransaction (t: Transaction, fn: Function) {
77 if (t) return t.afterCommit(() => fn())
78
79 return fn()
80}
81
75// --------------------------------------------------------------------------- 82// ---------------------------------------------------------------------------
76 83
77export { 84export {
78 resetSequelizeInstance, 85 resetSequelizeInstance,
79 retryTransactionWrapper, 86 retryTransactionWrapper,
80 transactionRetryer, 87 transactionRetryer,
81 updateInstanceWithAnother 88 updateInstanceWithAnother,
89 afterCommitIfTransaction
82} 90}