Is there a formatter of pg-promise to format logical clauses especially in WHERE
clauses, and SET
clauses (in sql UPDATE
)? Like connecting multiple keys and values of an object passed alongside a WHERE
clause with AND
s without repeated writing a named or numbered parameter in SQL for each key and value.
As or similar to the following:
somePgPromiseLibFunction("WHERE ${this:name} = ${this:somePgpFormatter}", {a: 1, b: 2, c: 3});
generates:
"WHERE a = 1 AND b = 2 AND c = 3"
and
somePgPromiseLibFunction("UPDATE some_table_name SET ${this:name} = ${this:somePgpFormatter} WHERE some_criteria", {a: 1, b: 2, c: 3});
generates:
"UPDATE some_table_name SET a = 1, b = 2, c = 3 WHERE some_criteria"
I know one can reference this
and use ${this:name}
and ${this:csv}
forINSERT
clauses, yielding a great advantage in developers' hands by removing the necessity of repeatedly typing, and modifying the INSERT
and VALUES
clauses. This makes the queries immune to schema change.