-
Notifications
You must be signed in to change notification settings - Fork 76
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
feature: Parameterized queries and transaction API #39
Conversation
4dee36e
to
65b3d2e
Compare
dc7be6a
to
94d902b
Compare
cebca90
to
f4cab07
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work! I think it's quite clean and easy to follow, I've left a few nits and comments mostly focusing on clarity.
I think the only design decision I'm not sure about is the transaction rollback API. It might be worth getting rid of it and just letting any error result in a rollback and needing the user to handle it. I think no transactions should aim to fail and be rolled back, so any rollbacks should be viewed as the internal preparation for the error handling logic left to the user.
Thanks @msfstef! I've addressed everything in your review. For the transactions, |
@samwillis I like the idea of allowing the user to perform their cleanup within the transaction - though the cleanup will still hold the lock without strictly needing it. Might be still worth documenting that transactions get rolled back on any error though regardless of whether Looks good, ready to merge! |
Is there a build of this with the changes somewhere? It would be nice to take it out for a spin! |
Hey @AntonOfTheWoods (and anyone else), There is a dev build of the latest changes from the tip of my stacked PRs linked on #48. You can download and try it out. We are planning to do a release early next week after a few final checks. |
PGlite driver for Electric Builds on parameterized query support for PGlite: electric-sql/pglite#39 --------- Co-authored-by: msfstef <msfstef@gmail.com>
PGlite driver for Electric Builds on parameterized query support for PGlite: electric-sql/pglite#39 --------- Co-authored-by: msfstef <msfstef@gmail.com>
PGlite driver for Electric Builds on parameterized query support for PGlite: electric-sql/pglite#39 --------- Co-authored-by: msfstef <msfstef@gmail.com>
PGlite driver for Electric Builds on parameterized query support for PGlite: electric-sql/pglite#39 --------- Co-authored-by: msfstef <msfstef@gmail.com>
PGlite driver for Electric Builds on parameterized query support for PGlite: electric-sql/pglite#39 --------- Co-authored-by: msfstef <msfstef@gmail.com>
PGlite driver for Electric Builds on parameterized query support for PGlite: electric-sql/pglite#39 --------- Co-authored-by: msfstef <msfstef@gmail.com>
PGlite driver for Electric Builds on parameterized query support for PGlite: electric-sql/pglite#39 --------- Co-authored-by: msfstef <msfstef@gmail.com>
PGlite driver for Electric Builds on parameterized query support for PGlite: electric-sql/pglite#39 --------- Co-authored-by: msfstef <msfstef@gmail.com>
Each PGlite instance (in that PR) has two methods to run a query:
.query(sql, params)
: execute a single statement, optionally with params. Returns single result object.exec(sql)
: execute one or more statements, no params. Returns array of result objects, one for each statement.I split this into two as it makes it easer to know if you are getting one or multiple result objects. Internally the first uses the extended protocol which only supports a single statement, the latter the simple protocol that can run multiple statements but with no params.
Node: this is a breaking change, what was
.query(sql)
is now.exec(sql)
.It also has a
.transaction((tx) => {})
api for interactive transactions. Eachtx
object also has the same.query
and.exec
methods, along with a.rollback()
.Finally there is also a
.execProtocol(msg: uInt8Array)
method that allows users to execute raw pg-protocl message.If anyone wants to try this, there is a build including this linked from: #48
Fixes #17, Fixes #31, Fixes #29, see also: electric-sql/postgres-wasm#3, electric-sql/postgres-wasm#4