X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fdatabase-utils.ts;h=aedcc5e6409d89861462352f8dfc92f151d3ef95;hb=f443a74649174b2f9347c158e30f8ac7aa3e958a;hp=422774022ac549168faca01afa2a3b247c373c5d;hpb=764b1a14fc494f2cfd7ea590d2f07b01df65c7ad;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index 422774022..aedcc5e64 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts @@ -1,6 +1,6 @@ -import * as retry from 'async/retry' -import * as Bluebird from 'bluebird' -import { BindOrReplacements, QueryTypes, Transaction } from 'sequelize' +import retry from 'async/retry' +import Bluebird from 'bluebird' +import { Transaction } from 'sequelize' import { Model } from 'sequelize-typescript' import { sequelizeTypescript } from '@server/initializers/database' import { logger } from './logger' @@ -95,18 +95,6 @@ function deleteAllModels > (models: T[], transa return Promise.all(models.map(f => f.destroy({ transaction }))) } -// Sequelize always skip the update if we only update updatedAt field -function setAsUpdated (table: string, id: number, transaction?: Transaction) { - return sequelizeTypescript.query( - `UPDATE "${table}" SET "updatedAt" = :updatedAt WHERE id = :id`, - { - replacements: { table, id, updatedAt: new Date() }, - type: QueryTypes.UPDATE, - transaction - } - ) -} - // --------------------------------------------------------------------------- function runInReadCommittedTransaction (fn: (t: Transaction) => Promise) { @@ -123,19 +111,6 @@ function afterCommitIfTransaction (t: Transaction, fn: Function) { // --------------------------------------------------------------------------- -function doesExist (query: string, bind?: BindOrReplacements) { - const options = { - type: QueryTypes.SELECT as QueryTypes.SELECT, - bind, - raw: true - } - - return sequelizeTypescript.query(query, options) - .then(results => results.length === 1) -} - -// --------------------------------------------------------------------------- - export { resetSequelizeInstance, retryTransactionWrapper, @@ -144,7 +119,5 @@ export { afterCommitIfTransaction, filterNonExistingModels, deleteAllModels, - setAsUpdated, - runInReadCommittedTransaction, - doesExist + runInReadCommittedTransaction }