-
-
Notifications
You must be signed in to change notification settings - Fork 194
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
Diesel integration #658
Diesel integration #658
Conversation
@weiznich I would greatly appreciate if you could let me know if you think this is a good approach 🙏 |
@tyt2y3 @billy1624 This is ready for a first review, we still have to wait for the next diesel release before we can merge though |
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.
From the diesel side the implementation looks OK. The one thing I personally would try to improve is enabling prepared statement caching at least for some queries at it really helps with performance.
DB: Backend, | ||
{ | ||
fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> { | ||
out.unsafe_to_cache_prepared(); |
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.
It might be useful to only call this method depending on whether sea-query believes that a prepared statement is meaningful to cache or not. It will significantly improve performance for queries that are executed more than once.
Diesel generally tries to cache all queries that are somewhat static, which means all queries that do not contain a user input dependent component (beside specific bind parameters).
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.
Yeah that's a good point, I think it will require a hint from sea-query side to implement that but we could offer an API that the user can specify (build_diesel_cached
or something). I am unsure how the caching exactly works when using a pool though? Usually the prepared statement is per connection, does diesel try to re-use the same connection? @tyt2y3 @billy1624 if you have any experience with that from the sqlx side that we could translate to diesel that would be super!
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.
It might be already worth to have a simple heuristics there: There are no bound paramaters -> cache the query, as it does not change for different calls.
For more targeted caching you would need to access the query ast somehow to check if there is for example no IN
expression with a variable number of binds in there or no INSERT
statement with a variable number of rows.
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.
Also there is quite a lot of detailed documentation of diesels query caching here: https://docs.diesel.rs/2.1.x/diesel/connection/statement_cache/index.html#a-primer-on-prepared-statement-caching-in-diesel
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.
Thanks for the info. May be later we can have an API that walks the AST and return whether:
- any custom expression used
- any
in
andnot_in
clause - insert many
Sure, I am okay with it |
@tyt2y3 Ready for review |
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: dtolnay/rust-toolchain@stable | ||
- run: cargo update --manifest-path sea-query-diesel/Cargo.toml --workspace -p bigdecimal:0.4.1 --precise 0.3.1 |
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.
This shouldn't be required anymore as diesel 2.1.1 added support for bigdecimal 0.4: https://crates.io/crates/diesel/2.1.1/dependencies
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.
Ha the issue is on sea-query side, they only support 0.3 and the resolver takes 0.4 for diesel so it causes a build failure because the types are incompatible. Its a PITA that we still don't have a way to pin a sub dependency without a lockfile.
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.
Thank you
Released in https://crates.io/crates/sea-query-diesel/0.1.0 |
Thanks much appreciated! |
PR Info
See discussion: #168
BLOCKED BY diesel-rs/diesel#3691 and diesel-rs/diesel#3694
New Features