Support pg-promise Query Files with Named Parameters
cmcnicoll opened this issue · 2 comments
cmcnicoll commented
tconbeer commented
From pg-promise docs:
Named Parameters
When a query method is parameterized with values as an object, the formatting engine expects the query to use the Named Parameter syntax $*propName*
, with *
being any of the following open-close pairs: {}
, ()
, <>
, []
, //
.
// We can use every supported variable syntax at the same time, if needed:
await db.none('INSERT INTO users(first_name, last_name, age) VALUES(${name.first}, $<name.last>, $/age/)', {
name: {first: 'John', last: 'Dow'},
age: 30
});
cmcnicoll commented
Here is the workaround I've been using:
- Run a script to quote named parameters in query file
example.sql
:
select * from users where id = '${id}'
- Use sqlfmt via dbt Power User
- Test query manually
- Run another script to unquote named parameters
- Test query in app