Broken SQL when using ST_GeographyFromText('SRID=4326;POINT(:lng :lat)')
Closed this issue · 1 comments
micaelomota commented
Hi. Thank you for maintaining this incredibly useful project!
I'm trying to bind named parameters in the following query:
SELECT ST_GeographyFromText('SRID=4326;POINT(:lng :lat)') as coordinates from myTable;
The output always keeps :lng :lat
. Is it supported by the library? If yes, how can I get it running?
micaelomota commented
For those having the same problem, I solved building my own script to bind it.
export function pgQuery(str: string, payload: Record<string, any>): string {
let resultStr = str;
for (const key of Object.keys(payload)) {
let value = payload[key];
if (typeof value === 'object' && value != null) {
value = JSON.stringify(value);
}
if (typeof value === 'string') {
value = `'${value.replace("'", "''")}'`;
}
resultStr = resultStr.replace(new RegExp(`:${key}`, 'g'), value);
}
return resultStr;
}