test-easy-psql
Version:
Welcome to the test-easy-psql documentation! test-easy-psql is a simple intermediary for querying data in PostgreSQL databases. Whether you're a beginner or an experienced developer, this documentation will help you get started with test-easy-psql and lev
31 lines (30 loc) • 678 B
JavaScript
;
class RawSQL {
constructor(sql, args = []) {
this.sql = sql;
this.args = args;
}
__replace_alias(alias) {
if (!alias) {
return this.sql;
}
let length = this.sql.split("__alias__").length - 1;
let str = this.sql;
while (length > 0) {
str = str.replace("__alias__", alias);
length--;
}
return str;
}
__getFormattedSQL(index = 1, alias) {
let length = this.sql.split("?").length - 1;
let str = this.__replace_alias(alias);
while (length > 0) {
str = str.replace("?", `$${index}`);
index++;
length--;
}
return [str, this.args, index];
}
}
module.exports = RawSQL;