Skip to content

sql.savepoint as tagged template function? #201

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

Closed
JAForbes opened this issue Jul 26, 2021 · 2 comments · Fixed by #259
Closed

sql.savepoint as tagged template function? #201

JAForbes opened this issue Jul 26, 2021 · 2 comments · Fixed by #259
Labels
enhancement New feature or request

Comments

@JAForbes
Copy link
Contributor

I imagine savepoint will often be used for a single query. Would it make sense to offer sql.savepoint as both a callback and a tagged template function?

E.g.

let unavailable;
sql.savepoint`insert into users(username) ${username}`.catch( () => unavailable = true )

vs

let unavailable;
sql.savepoint( sql => sql`insert into users(username) ${username}` ).catch( () => unavailable = true )

It might not be worth the sugar, but I thought I'd mention the idea because all my savepoint usages so far had been for a single query.

@porsager
Copy link
Owner

Yeah, that makes sense, but it breaks a bit with trying to keep queries inside a sql named tagged function.

The reason for keeping SQL syntax only in sql named tagged functions is to help eg. syntax highlighters, and also (my own usage), searching for sql` will show me all SQL queries.

How about sql``.savepoint() instead perhaps?

@JAForbes
Copy link
Contributor Author

Yeah way better 👏

@porsager porsager added the enhancement New feature or request label Jul 30, 2021
@porsager porsager modified the milestone: v2 Sep 19, 2021
@porsager porsager mentioned this issue Jan 11, 2022
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants