-
-
Notifications
You must be signed in to change notification settings - Fork 540
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
Allow creating a sea_orm::Databse from sqlx::ConnectOptions #434
Conversation
575c8b4
to
9f4e204
Compare
@billy1624 Can you approve the run now? |
Sure! |
0fce39b
to
8711d89
Compare
I think the rocket example that failed has beed fixed. Also I have went through and added Hash, PartialEq, Clone derives on all types where possible, in the second commit. |
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'm curious about why we need to derive Hash
?
src/database/mod.rs
Outdated
/// Defines the configuration options of a database | ||
#[derive(Debug)] | ||
#[derive(Debug, Clone)] | ||
pub struct ConnectOptions { | ||
/// The URI of the database | ||
pub(crate) url: String, | ||
/// The database sqlx::ConnectOptions used to connect to the database. | ||
pub(crate) connect_options: SqlxConnectOptions, | ||
/// The URI of the database, if this struct was created from an URI string, otherwise None | ||
pub(crate) url: Option<String>, |
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.
We should make this an enum with two variants
SqlxConnectOptions
: wrapper enum of all supported databases' connection optionConnectionOptions
: raw url with some other connection option included in the oldConnectOptions
struct
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.
First I removed the url entirely. Then I put it back because of the url() method.
The best solution would be to remove the url string field from here and then have the sqlx::ConnectOptions have a method for getting a string url from them representing their content and then we could remove the url field from here. However this would need to be implemented in sqlx.
This PR has changed the url() in a way that it will only return something if it was created from an url because otherwise we currently cannot get the url from the connect_options.
Do we need to have the method url()? If we could remove it then we can also just get rid of the url field here.
The best option would be to have the sqlx::ConnectOptions trait have a to_url() -> String method that is implemented in sqlx for all the ConnectOptions implmentations IMO.
I'm just too lazy to do that myself that seems like a lot of work :D
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 PR has changed the url() in a way that it will only return something if it was created from an url because otherwise we currently cannot get the url from the connect_options.
Which is pretty confusing IMO... :\
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.
What do you think we should do with the url? Should we keep the url() method? Should that only return the url if the sea_orm::ConenctOptions was created from an url string?
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 think we can keep the ConnectOptions
untouched. And introduce a new trait (e.g. ConnectionOptionTrait
) that convert any kinds of DatabaseOptions into Database
. Then, Database::connect()
method takes any ConnectionOptionTrait
.
Make sense? CC @tyt2y3
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.
@billy1624 No this doesn't answer the question about what should we return from the DatabaseConnection
when get_url
is called if the DatabaseConnection
was created from a sqlx::ConnectOptions
implementation like SqliteConnectOptions
?
About ConnectionOptionTrait
we don't need that to be able to implement creating DatabaseConnection
from both urls and both sqlx::ConnectOptions
implementations. You can just do what I already did in this PR implementing with TryFrom
.
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.
@billy1624 any update about this? Specifically about what should get_url
return if the DatabaseConnection
was not created from an url string but from an sqlx::ConnectOptions
e.g.: SqliteConnectOptions
?
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.
@billy1624 @tyt2y3 Anyone?
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.
Hey @05storm26, sorry for the delay. I will get back to you ASAP
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.
Hi @billy1624 the required sqlx commits have been merged so this could be merged after the review is completed.
Could you take a look at this conversation again?
I am not sure. Maybe someone needs it. If you want to use ConnectOptions in a hashmap as keys maybe. I don't know why you would do that just an idea. I am generally on the side that we should implement for all types as much from the traits: Clone, Clone, PartialEq, Hash as possible. |
7ce941b
to
33a87d7
Compare
Will launchbadge/sqlx#1610 be in SQLx 0.6? And when will 0.6 lands? |
Due to changes requested by sqlx owner I had to make a small change in this pr as well. |
ca64c37
to
0c91a5a
Compare
Oh, I wonder why the tests failed |
Seems like maybe there was a Currently there is two commits in this PR the actual change and also a second one which adds these useful trait derives on multiple types. Probably that is the one breaking. Should I just remove that? Or should we fix this in |
But I am still not sure what to do with the |
I think we can remove the |
Now that I re-think this. Shouldn't we just add a method to create sea-orm/src/driver/sqlx_mysql.rs Lines 66 to 72 in 483de17
|
7cd0537
to
4699f7d
Compare
@billy1624 I have rebased this on top of master. Please run the tests for it. |
bedb6e8
to
b77cac7
Compare
For me it looks like that should be constructed by calling |
Is
|
b452118
to
4852645
Compare
I don't think this is ever going to be merged so I am just gonna let it go. |
Hey @05storm26, sorry and thanks again for the effort! |
Seems like doing what is requested in #398 is too difficult.
However allowing users to create a
sea_orm::Database
fromsqlx::ConnectOptions
implementations likeMySqlConnectOptions
seems to be doable.For me this is good enough.
Also I have added a new feature options
sqlx-any
. If this is enabled the sqlx isany
feature is turned on and you can create ansea_orm::Database
fromAnyConnectOptions
as well.However this depends on this PR launchbadge/sqlx#1610 (not yet merged!)MERGED and released