2021-06-10 07:43:55 -05:00
|
|
|
import { QueryTypes, Sequelize, Transaction } from 'sequelize'
|
|
|
|
|
2021-06-10 09:57:13 -05:00
|
|
|
/**
|
|
|
|
*
|
Fix various typos
Found via `codespell -q 3 -S ./CREDITS.md,./CHANGELOG.md,./client/src/locale,./yarn.lock,./client/yarn.lock -L doubleclick,followings,nd,ot,ro,serie,splitted,tread,truthy`
2022-06-07 08:45:06 -05:00
|
|
|
* Abstract builder to run video SQL queries
|
2021-06-10 09:57:13 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-11-02 05:00:40 -05:00
|
|
|
export class AbstractRunQuery {
|
2021-06-10 07:43:55 -05:00
|
|
|
protected query: string
|
|
|
|
protected replacements: any = {}
|
|
|
|
|
2022-03-03 03:23:44 -06:00
|
|
|
constructor (protected readonly sequelize: Sequelize) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected runQuery (options: { nest?: boolean, transaction?: Transaction, logging?: boolean } = {}) {
|
2021-06-11 07:09:33 -05:00
|
|
|
const queryOptions = {
|
|
|
|
transaction: options.transaction,
|
|
|
|
logging: options.logging,
|
2021-06-10 07:43:55 -05:00
|
|
|
replacements: this.replacements,
|
|
|
|
type: QueryTypes.SELECT as QueryTypes.SELECT,
|
2022-03-03 03:23:44 -06:00
|
|
|
nest: options.nest ?? false
|
2021-06-10 07:43:55 -05:00
|
|
|
}
|
|
|
|
|
2021-06-11 07:09:33 -05:00
|
|
|
return this.sequelize.query<any>(this.query, queryOptions)
|
2021-06-10 07:43:55 -05:00
|
|
|
}
|
2022-05-05 03:29:35 -05:00
|
|
|
|
|
|
|
protected buildSelect (entities: string[]) {
|
|
|
|
return `SELECT ${entities.join(', ')} `
|
|
|
|
}
|
2021-06-10 07:43:55 -05:00
|
|
|
}
|