]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/models/video/sql/shared/abstract-videos-query-builder.ts
Use raw SQL for most of video queries
[github/Chocobozzz/PeerTube.git] / server / models / video / sql / shared / abstract-videos-query-builder.ts
... / ...
CommitLineData
1import { QueryTypes, Sequelize, Transaction } from 'sequelize'
2import { logger } from '@server/helpers/logger'
3
4/**
5 *
6 * Abstact builder to run video SQL queries
7 *
8 */
9
10export class AbstractVideosQueryBuilder {
11 protected sequelize: Sequelize
12
13 protected query: string
14 protected replacements: any = {}
15
16 protected runQuery (options: { transaction?: Transaction, logging?: boolean } = {}) {
17 logger.debug('Running videos query.', { query: this.query, replacements: this.replacements })
18
19 const queryOptions = {
20 transaction: options.transaction,
21 logging: options.logging,
22 replacements: this.replacements,
23 type: QueryTypes.SELECT as QueryTypes.SELECT,
24 next: false
25 }
26
27 return this.sequelize.query<any>(this.query, queryOptions)
28 }
29}