From fa47956ecf51a6d5d10aeb25d2e4db3da90c7d58 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 28 Jul 2021 10:32:40 +0200 Subject: Filter host for channels and playlists search --- server/models/shared/index.ts | 2 ++ server/models/shared/query.ts | 17 +++++++++++++++++ server/models/shared/update.ts | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 server/models/shared/index.ts create mode 100644 server/models/shared/query.ts create mode 100644 server/models/shared/update.ts (limited to 'server/models/shared') diff --git a/server/models/shared/index.ts b/server/models/shared/index.ts new file mode 100644 index 000000000..5b97510e0 --- /dev/null +++ b/server/models/shared/index.ts @@ -0,0 +1,2 @@ +export * from './query' +export * from './update' diff --git a/server/models/shared/query.ts b/server/models/shared/query.ts new file mode 100644 index 000000000..036cc13c6 --- /dev/null +++ b/server/models/shared/query.ts @@ -0,0 +1,17 @@ +import { BindOrReplacements, QueryTypes } from 'sequelize' +import { sequelizeTypescript } from '@server/initializers/database' + +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 { + doesExist +} diff --git a/server/models/shared/update.ts b/server/models/shared/update.ts new file mode 100644 index 000000000..d338211e3 --- /dev/null +++ b/server/models/shared/update.ts @@ -0,0 +1,18 @@ +import { QueryTypes, Transaction } from 'sequelize' +import { sequelizeTypescript } from '@server/initializers/database' + +// 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 + } + ) +} + +export { + setAsUpdated +} -- cgit v1.2.3