puddysql
Version:
🍮 Powerful SQL toolkit for Node.js, built with flexibility and structure in mind. Easily manage SQLite3/PostgreSQL, advanced queries, smart tag systems, and full JSON-friendly filters.
26 lines (25 loc) • 1.2 kB
text/typescript
/**
* Converts PostgreSQL-style SQL placeholders ($1, $2, ...) to MySQL-style placeholders (?).
* Maintains full compatibility with repeated and unordered params.
*
* @param {string} query - The PostgreSQL-style query.
* @param {any[]} params - Parameters corresponding to placeholders.
* @param {(reason?: any) => void} [errCallback]
* @returns {{ query: string, params: any[] }} - MySQL-compatible query and reordered parameters.
*/
export function convertPgToMySQLSyntax(query: string, params: any[], errCallback?: (reason?: any) => void): {
query: string;
params: any[];
};
/**
* Validates if a PostgreSQL-style query with $1, $2, ... placeholders
* matches the number of parameters in the params array.
* Ignores other placeholder styles like :name or ?.
*
* @param {string} query - SQL query with $n placeholders.
* @param {any[]} params - Array of parameter values.
* @param {(reason?: any) => void} [errCallback]
* @returns {true} Returns true if valid.
* @throws {Error} Throws if placeholders reference missing parameters or invalid indexes.
*/
export function validatePostgresParams(query: string, params: any[], errCallback?: (reason?: any) => void): true;