diff options
Diffstat (limited to 'server/helpers/database-utils.ts')
-rw-r--r-- | server/helpers/database-utils.ts | 10 |
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' | |||
2 | import * as Bluebird from 'bluebird' | 2 | import * as Bluebird from 'bluebird' |
3 | import { Model } from 'sequelize-typescript' | 3 | import { Model } from 'sequelize-typescript' |
4 | import { logger } from './logger' | 4 | import { logger } from './logger' |
5 | import { Transaction } from 'sequelize' | ||
5 | 6 | ||
6 | function retryTransactionWrapper <T, A, B, C> ( | 7 | function 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 | ||
76 | function afterCommitIfTransaction (t: Transaction, fn: Function) { | ||
77 | if (t) return t.afterCommit(() => fn()) | ||
78 | |||
79 | return fn() | ||
80 | } | ||
81 | |||
75 | // --------------------------------------------------------------------------- | 82 | // --------------------------------------------------------------------------- |
76 | 83 | ||
77 | export { | 84 | export { |
78 | resetSequelizeInstance, | 85 | resetSequelizeInstance, |
79 | retryTransactionWrapper, | 86 | retryTransactionWrapper, |
80 | transactionRetryer, | 87 | transactionRetryer, |
81 | updateInstanceWithAnother | 88 | updateInstanceWithAnother, |
89 | afterCommitIfTransaction | ||
82 | } | 90 | } |