aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/models/shared/abstract-run-query.ts
blob: f1182c7be3f30fdddbbd0af40f8db83eb8e1a3e9 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                              
 





                                           
                               


                                  




                                                                                                       


                                       

                                                   
                                 

     
                                                              
   



                                              
 
import { QueryTypes, Sequelize, Transaction } from 'sequelize'

/**
 *
 * Abstact builder to run video SQL queries
 *
 */

export class AbstractRunQuery {
  protected query: string
  protected replacements: any = {}

  constructor (protected readonly sequelize: Sequelize) {

  }

  protected 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
    }

    return this.sequelize.query<any>(this.query, queryOptions)
  }

  protected buildSelect (entities: string[]) {
    return `SELECT ${entities.join(', ')} `
  }
}