You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
918 B
TypeScript
39 lines
918 B
TypeScript
import { QueryTypes, Sequelize, Transaction } from 'sequelize'
|
|||
|
|||
/**
|
|||
*
|
|||
* Abstract builder to run video SQL queries
|
|||
*
|
|||
*/
|
|||
|
|||
export class AbstractRunQuery {
|
|||
protected query: string
|
|||
protected replacements: any = {}
|
|||
|
|||
protected queryConfig = ''
|
|||
|
|||
constructor (protected readonly sequelize: Sequelize) {
|
|||
|
|||
}
|
|||
|
|||
protected async runQuery (options: { nest?: boolean, transaction?: Transaction, logging?: boolean } = {}) {
|
|||
const queryOptions = {
|
|||
transaction: options.transaction,
|
|||
logging: options.logging,
|
|||
replacements: this.replacements,
|
|||
type: QueryTypes.SELECT as QueryTypes.SELECT,
|
|||
nest: options.nest ?? false
|
|||
}
|
|||
|
|||
if (this.queryConfig) {
|
|||
await this.sequelize.query(this.queryConfig, queryOptions)
|
|||
}
|
|||
|
|||
return this.sequelize.query<any>(this.query, queryOptions)
|
|||
}
|
|||
|
|||
protected buildSelect (entities: string[]) {
|
|||
return `SELECT ${entities.join(', ')} `
|
|||
}
|
|||
}
|