import sqlString from "sqlstring" ; /** ===========================================================================
 * Types & Config
 * ============================================================================
 */ export interface SQLVariables { [ key ] : string | number ; } /** ===========================================================================
 * SQL Queries Utils
 * ============================================================================
 */ /**
 * Trim duplicate whitespace and newlines.
 */ export const trimQuery = ( q ) : string => { return q . replace ( /\s+/g , " " ) . replace ( /\n/ , "" ) ; } ; /**
 * Escape and format a user submitted address into a SQL query string and
 * return a URI encoded query string.
 */ export const getSqlQueryString = ( sql , variables = { } , enforceVariablesExist = true ) : string => { let query = sql ; Object . entries ( variables ) . forEach ( ( [ key , value ] ) => { const pattern = `@${ key }` ; if ( enforceVariablesExist && ! query . includes ( pattern ) ) { throw new Error ( `Invalid variables received for query, expected: ${ pattern }` ) ; } query = query . replace ( new RegExp ( pattern , "g" ) , sqlString . escape ( value ) ) ; } ) ; return trimQuery ( query ) ; } ;