import { PostgresConnectionParams } from "../../types/integrations/postgres" ; import { decryptDataSourceParams } from "../services/datasource" ; import { runPostgresQuery } from "../services/postgres" ; import SqlIntegration from "./SqlIntegration" ; export default class Postgres extends SqlIntegration { params : PostgresConnectionParams ; setParams ( encryptedParams ) { this . params = decryptDataSourceParams < PostgresConnectionParams > ( encryptedParams ) ; } getSensitiveParamKeys ( ) { return [ "password" , "caCert" , "clientCert" , "clientKey" ] ; } runQuery ( sql ) { return runPostgresQuery ( this . params , sql ) ; } getSchema ( ) { return this . params . defaultSchema || "" ; } percentile ( col , percentile ) { return `PERCENTILE_DISC ( ${ percentile } ) WITHIN GROUP (ORDER BY ${ col })` ; } dateDiff ( startCol , endCol ) { return `${ endCol }::DATE - ${ startCol }::DATE` ; } avg ( col ) { return `AVG(${ col }::float)` ; } formatDate ( col ) { return `to_char(${ col }, 'YYYY-MM-DD')` ; } }