import { MysqlConnectionParams } from "../../types/integrations/mysql" ; import { decryptDataSourceParams } from "../services/datasource" ; import SqlIntegration from "./SqlIntegration" ; import mysql , { RowDataPacket } from "mysql2/promise" ; export default class Mysql extends SqlIntegration { params : MysqlConnectionParams ; setParams ( encryptedParams ) { this . params = decryptDataSourceParams < MysqlConnectionParams > ( encryptedParams ) ; } getSensitiveParamKeys ( ) { return [ "password" ] ; } async runQuery ( sql ) { const conn = await mysql . createConnection ( { host : this . params . host , port : this . params . port , user : this . params . user , password : this . params . password , database : this . params . database , } ) ; const [ rows ] = await conn . query ( sql ) ; return rows as RowDataPacket [ ] ; } percentile ( ) { return `0` ; } dateDiff ( startCol , endCol ) { return `DATEDIFF(${ endCol }, ${ startCol })` ; } addHours ( col , hours ) { return `DATE_ADD(${ col }, INTERVAL ${ hours } HOUR)` ; } subtractHalfHour ( col ) { return `SUBTIME(${ col }, "0:30")` ; } regexMatch ( col , regex ) { return `${ col } REGEXP '${ regex }'` ; } dateTrunc ( col ) { return `DATE(${ col })` ; } formatDate ( col ) { return `DATE_FORMAT(${ col }, "%Y-%m-%d")` ; } castToString ( col ) { return `cast(${ col } as char)` ; } }