PeerTube/server/models/shared/abstract-run-query.ts

29 lines
685 B
TypeScript
Raw Normal View History

2021-06-10 14:43:55 +02:00
import { QueryTypes, Sequelize, Transaction } from 'sequelize'
2021-06-10 16:57:13 +02:00
/**
*
* Abstact builder to run video SQL queries
*
*/
2021-11-02 11:00:40 +01:00
export class AbstractRunQuery {
2021-06-10 14:43:55 +02:00
protected query: string
protected replacements: any = {}
2022-03-03 10:23:44 +01:00
constructor (protected readonly sequelize: Sequelize) {
}
protected runQuery (options: { nest?: boolean, transaction?: Transaction, logging?: boolean } = {}) {
2021-06-11 14:09:33 +02:00
const queryOptions = {
transaction: options.transaction,
logging: options.logging,
2021-06-10 14:43:55 +02:00
replacements: this.replacements,
type: QueryTypes.SELECT as QueryTypes.SELECT,
2022-03-03 10:23:44 +01:00
nest: options.nest ?? false
2021-06-10 14:43:55 +02:00
}
2021-06-11 14:09:33 +02:00
return this.sequelize.query<any>(this.query, queryOptions)
2021-06-10 14:43:55 +02:00
}
}