-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Proposal: AnyPool
compatibility with query builders (e.g. sea-query
)
#1225
Comments
I think you can write a generalized That say, from my understanding, Otherwise, I think it is better for you to have an |
There isn't always a common subset that's sufficient to represent all the queries (see AUTOINCREMENT for instance). And identifier quotes can be useful as well.
|
@nitnelave I agree that it'd be nice to have an There are some differences at the protocol level to look out too. For example, MySQL has |
I'm not sure we're talking about the same thing:
|
Yes I understand your point. Let me illustrate: trait AnyQuery {
fn build(&self, type: AnyKind) -> String;
} That way any struct implementing this interface can be accepted. Edited snippet. |
Ah, yes, that would work :) Sorry for misunderstanding. Something like this enum? sqlx/sqlx-core/src/any/kind.rs Lines 5 to 17 in b6e1275
|
Yes, I'd comfortably implement the |
I put together a draft of PR. I ran into the limitation that the trait couldn't return |
Isn't it the other way around, owned object easier to handle than ref? Btw, it's better to have consent from the maintainer whether it aligns with the overall design. |
Okay, I've tried very hard to make it work with both &str and String without just converting everything to String, and I just can't figure it out, without propagating a generics parameter all the way to the Query type (which would be an interface break). There are ownership problems when you create the string deep inside the framework code. A simpler solution is this interface: let query : &str = sqlx::Select(...).build(any_pool.kind());
sqlx::query(&query).execute(&any_pool);
WDYT? |
Yes, I think an interface addition is a small enough change. |
Hey,
When using the
AnyPool
connection, you have to adapt the query to the various quirks of the DB (e.g. sqlite and autoincrement). Since you cannot write truly generic queries, that severely limits the usefulness ofAnyPool
.However, there are some crates specifically made to solve this problem: query builders (e.g. sea-query). They can generate the query for various DB. Since we can't extract the DB type from
AnyPool
, it would be great if it was aware of sea-query and could realize the query with the right engine.(Note that query builders don't work with the compile-time verification, but it's not a problem since it doesn't work with
AnyPool
anyway, and it's optional)My proposal, in more concrete terms:
sea-query
feature guard.query
andquery_as
that takes asea-query
and builds it with the correct builder, for all DB backends (supported), and delegation fromAnyPool
to the correct (dynamic) backend.It would require calling the
to_string
function with the correct builder, for all query types. I also created an issue in sea-query to add a trait for all buildable query types, to facilitate this work.If you agree with the plan, I can help put it into action.
The text was updated successfully, but these errors were encountered: