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.ts31
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 @@
1import * as retry from 'async/retry' 1import * as retry from 'async/retry'
2import * as Bluebird from 'bluebird' 2import * as Bluebird from 'bluebird'
3import { BindOrReplacements, QueryTypes, Transaction } from 'sequelize' 3import { Transaction } from 'sequelize'
4import { Model } from 'sequelize-typescript' 4import { Model } from 'sequelize-typescript'
5import { sequelizeTypescript } from '@server/initializers/database' 5import { sequelizeTypescript } from '@server/initializers/database'
6import { logger } from './logger' 6import { 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
99function 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
112function runInReadCommittedTransaction <T> (fn: (t: Transaction) => Promise<T>) { 100function runInReadCommittedTransaction <T> (fn: (t: Transaction) => Promise<T>) {
@@ -123,19 +111,6 @@ function afterCommitIfTransaction (t: Transaction, fn: Function) {
123 111
124// --------------------------------------------------------------------------- 112// ---------------------------------------------------------------------------
125 113
126function 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
139export { 114export {
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}