-
-
Notifications
You must be signed in to change notification settings - Fork 623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add taggedExecute helper #1539
base: master
Are you sure you want to change the base?
Add taggedExecute helper #1539
Conversation
Coverage reportThe coverage rate is The branch rate is
|
…en server versions
Something that I don't like but not sure how to handle well in a backwards compatible way. With addition of tagged templates based PS there will be 4 ways of sending parametrised sql, which potentially makes everything very confusing: // 1 - client side interpolation, PS-like but not "real" prepared statements:
const [rows1, columns1] = await connection.query('select ? as solution', ["parameter"]);
// 2 - real PS, prepare(sql) + execute(param) command the first time its called, execute(param) after
// api aims to mimic (1) but due to limitations of prepared statements there are differences
const [rows2, columns2] = await connection.execute('select ? as solution', ["parameter"]);
// 3 - named placeholders. Same as (2) but a bit easier to read
const [rows3, columns3] = await connection.execute('select :parameter as solution', { parameter: "parameter"});
// 4 - tagged template
const rows = await sql`select ${"parameter"} as solution`; Is having (3) and (4) too much? Given that (3) is relatively unknown, maybe we should deprecate it in favour of (4) ? |
might be a good idea to model api to match https://github.com/porsager/postgres#await-sql---result not sure though if it belongs to base driver or independent wrapper library |
add to docs: this extension should provide syntax highlighting with no additional config - https://marketplace.visualstudio.com/items?itemName=frigus02.vscode-sql-tagged-template-literals |
I'm leaning towards not merging this and creating separate package instead |
Existing external modules as of Nov 2023: |
RFC at this stage, but I think the feature was mentioned / requested few times in the past and looks like a safe and useful addition
At this stage I intentionally adding this to "real" prepared statements only ( AKA
.execute()
) and also to promise wrapper only. Also intentional is thatfields
part is not returned, no moreconst [rows] = await ...
destructuring. If fields are needed always possible to use slightly lower level.execute()
partially inspired by https://github.com/google/zx
examples: