diff options
Diffstat (limited to 'server/helpers/database-utils.ts')
-rw-r--r-- | server/helpers/database-utils.ts | 31 |
1 files changed, 2 insertions, 29 deletions
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index 422774022..ec35295df 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as retry from 'async/retry' | 1 | import * as retry from 'async/retry' |
2 | import * as Bluebird from 'bluebird' | 2 | import * as Bluebird from 'bluebird' |
3 | import { BindOrReplacements, QueryTypes, Transaction } from 'sequelize' | 3 | import { Transaction } from 'sequelize' |
4 | import { Model } from 'sequelize-typescript' | 4 | import { Model } from 'sequelize-typescript' |
5 | import { sequelizeTypescript } from '@server/initializers/database' | 5 | import { sequelizeTypescript } from '@server/initializers/database' |
6 | import { logger } from './logger' | 6 | import { logger } from './logger' |
@@ -95,18 +95,6 @@ function deleteAllModels <T extends Pick<Model, 'destroy'>> (models: T[], transa | |||
95 | return Promise.all(models.map(f => f.destroy({ transaction }))) | 95 | return Promise.all(models.map(f => f.destroy({ transaction }))) |
96 | } | 96 | } |
97 | 97 | ||
98 | // Sequelize always skip the update if we only update updatedAt field | ||
99 | function setAsUpdated (table: string, id: number, transaction?: Transaction) { | ||
100 | return sequelizeTypescript.query( | ||
101 | `UPDATE "${table}" SET "updatedAt" = :updatedAt WHERE id = :id`, | ||
102 | { | ||
103 | replacements: { table, id, updatedAt: new Date() }, | ||
104 | type: QueryTypes.UPDATE, | ||
105 | transaction | ||
106 | } | ||
107 | ) | ||
108 | } | ||
109 | |||
110 | // --------------------------------------------------------------------------- | 98 | // --------------------------------------------------------------------------- |
111 | 99 | ||
112 | function runInReadCommittedTransaction <T> (fn: (t: Transaction) => Promise<T>) { | 100 | function runInReadCommittedTransaction <T> (fn: (t: Transaction) => Promise<T>) { |
@@ -123,19 +111,6 @@ function afterCommitIfTransaction (t: Transaction, fn: Function) { | |||
123 | 111 | ||
124 | // --------------------------------------------------------------------------- | 112 | // --------------------------------------------------------------------------- |
125 | 113 | ||
126 | function doesExist (query: string, bind?: BindOrReplacements) { | ||
127 | const options = { | ||
128 | type: QueryTypes.SELECT as QueryTypes.SELECT, | ||
129 | bind, | ||
130 | raw: true | ||
131 | } | ||
132 | |||
133 | return sequelizeTypescript.query(query, options) | ||
134 | .then(results => results.length === 1) | ||
135 | } | ||
136 | |||
137 | // --------------------------------------------------------------------------- | ||
138 | |||
139 | export { | 114 | export { |
140 | resetSequelizeInstance, | 115 | resetSequelizeInstance, |
141 | retryTransactionWrapper, | 116 | retryTransactionWrapper, |
@@ -144,7 +119,5 @@ export { | |||
144 | afterCommitIfTransaction, | 119 | afterCommitIfTransaction, |
145 | filterNonExistingModels, | 120 | filterNonExistingModels, |
146 | deleteAllModels, | 121 | deleteAllModels, |
147 | setAsUpdated, | 122 | runInReadCommittedTransaction |
148 | runInReadCommittedTransaction, | ||
149 | doesExist | ||
150 | } | 123 | } |