-
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
Add a get_kind
method to Pool
#1228
Conversation
Note that I'm not entirely sure how other libraries can build on that with the feature guards. I.e. if we take Another way to do it would be to extract the Note that it shouldn't block merging this, since it at least allows to do the binding in the crates that depend on both. |
Can somebody review/merge this PR? |
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.
The only thing I'd recommend adding here is a derive for Copy, Clone, PartialEq, Eq
on AnyKind
, since it can currently only be passed around by reference thanks to a lack of a Copy implementation, and can't be equated without a match
.
@nitnelave I second the suggestion by @Dessix Also it's a bit weird for pub trait Database {
// ...
// pick one
const ANY_KIND: AnyKind;
fn any_kind() -> AnyKind;
} |
Sorry, i was on holidays the past 2 weeks. I'll have a look at it next week and apply the suggestions. |
Thanks for the review! @abonander It's not actually stateless: for most DBs it is, but for the I also added the method to the Pool, just forwarding it to the connection options in order to have a nicer interface. @Dessix Added the derives. |
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.
@nitnelave This needs to be compliant with disablement of the any
feature, as the sqlx-core::any
module is entirely omitted if this feature is disabled. Additionally, you should be using the relatively new sqlx-core::any::AnyKind
instead of creating the module sqlx-core::any_kind
, as this type has now been exposed by that module in the main branch.
I'd suggest you do this by:
- restarting from
HEAD
which has significant changes to theany
module - exposing
get_kind
as you have - Annotating get_kind and
use
clauses for conditional compilation based on theany
feature being enabled. If the destination crate for some of these changes is notsqlx-core
, you'll likely needcfg(feature = "sqlx-core/any")
instead of justcfg(feature = "any")
in those cases.
@Dessix I was trying to have the function be there regardless of whether the Updated as per your comment, ready for review! |
Gentle ping :) |
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.
Assuming I haven't missed anything, it should build with both any
and not-any
feature configurations, so I approve ^^
sqlx-core/src/connection.rs
Outdated
|
||
/// Returns the driver used for the connection. | ||
#[cfg(feature = "any")] | ||
fn get_kind(&self) -> AnyKind; |
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 is technically a backwards-incompatible change and so will need to be part of 0.6.0
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.
Additive changes are backward-compatible, unless you're describing trait-ABI compatibility? Since there is no official ABI for Rust yet, I don't think we need to consider that?
Ah, nevermind- this trait is unsealed...
It could be done without breakage by making a Kinded
trait under the any
module and exposing that for the implementations in question?
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.
You could just have an inherent method kind(&self) -> AnyKind
on AnyConnectOptions
and then an inherent method on Pool<Any>
that forwards to that. Would that suit your use case?
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.
Might be worth just releasing it as a breaking-change; it's not like it will benefit the performance semantics for anyone who would receive a patch update.
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.
So what's the way forward? Should we release this as a breaking change, or implement @abonander's proposal? (sorry I lost a bit of context on that PR over the months so I'd have to get back in to understand his proposal)
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.
I would prefer to just have it be an inherent method on Pool<Any>
if that suits the use-case. I don't think it's necessary to change a fundamental trait like this.
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.
Alright, I don't think I can make it any less intrusive like that, PTAL
Updated to minimize the changes, including not changing any traits. On the other hand, it only works for PTAL, it's ready for review. |
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 good to me, just a few nits left.
Stop making me reduce the patch, there won't be anything left! :D |
Should we merge this? It's been approved for a week. |
Yeah, sorry. I was waiting for it to go green but got busy and forgot. |
Thanks! |
This PR addresses #1225
It adds a
get_kind
method toPool
, going throughSharedPool
andConnectionOptions
to get the (dynamic forAny
) type of the connection.This will allow query builders to build the query based on which driver (and so which dialect) is used.
Note: The
sqlx-core/src/any/kind.rs
was moved tosqlx-core/src/any_kind.rs
because it's now needed for every DB, so it shouldn't be guarded by theany
feature.I didn't add any tests, because I'm not entirely sure where to add them, and there is not really any logic to test. The test (if any) should probably only check the interface, maybe in a test where we have a
&any_pool
and we check its.get_kind()
?