-
Notifications
You must be signed in to change notification settings - Fork 14
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 support for prepared statements #13
base: main
Are you sure you want to change the base?
Conversation
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.
Looks great! Thank you.
Could you write a test for what happens when the connection has been closed and then the statement is run. Thank you
Thank you very much for the code review. I wrote some tests and got inconsistent results depending on the target platform. 1. Running a normal
|
Hello, I used this version in a private project of mine, and tests failed. After a few hours of debugging, I found the problem. If you don't reset the prepared statement after an error occurs, this error will reappear when the prepared statement is used again. This is now solved, and I added the test case which triggered this bug by not resetting the prepared statement after each use. I also set a flag to indicate that these prepared statements are persistent. Thank you very much! :) |
Great detective work there! Bravo! That difference between the targets today is a bug. We'll have to make an issue for it. I'm confused by the Erlang one where the prepared statement works even though it was closed. Do you understand why it is that works? |
Thank you very much! <3 No, I have no clue why this behavior exists, but I can look into it when I have the motivation to do so. ;) Regarding the closing issue: It's probably not the best solution because I have no prior Erlang experience, and I'm probably somewhere on Mount Stupid (Dunning–Kruger effect), but my chain of thought is the following:
Since I also wrote connection pooling for my application, and I think this would be a generally useful feature, I would suggest the following:
I would be willing to implement this new feature in a new pull request, since I think this would be a great chance to get another code review from you. :3 Since I don't know if you even want this feature in your library, and it isn't that trivial IMHO, some input from you would be great! Either way, thank you very much! |
Hello :)
I added support for prepared query statements to improve overall performance when queries are reused.
Since both libraries (Erlang and JavaScript) use prepared statements under the hood when calling
query
, I split this function intoprepare
andquery_prepared
.I also updated every test that uses
sqlight.query
by introducing a helper function that ensures both functions return the same errors and results.I had to wrap the database connection in
sqlight_ffi.js
to keep track of the created prepared statements since the library requires that they be finalized before closing the connection. I think this isn't the most elegant solution, but I'm not aware of a better approach.I also updated the
README
example, theCHANGELOG
, and bumped the version to0.10.0
.Thank you very much for the great work, and I'm hoping I didn't miss anything this time. :)