Skip to content
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

sea_orm::DatabaseConnection should implement Clone by default #517

Closed
feelingnothing opened this issue Feb 12, 2022 · 4 comments · Fixed by #562
Closed

sea_orm::DatabaseConnection should implement Clone by default #517

feelingnothing opened this issue Feb 12, 2022 · 4 comments · Fixed by #562
Assignees
Milestone

Comments

@feelingnothing
Copy link

feelingnothing commented Feb 12, 2022

Because MockConnection is under an Arc - DatabaseConnection can implement Clone by default

#[cfg_attr(not(feature = "mock"), derive(Clone))]

MockDatabaseConnection(Arc<crate::MockDatabaseConnection>),

@billy1624
Copy link
Member

Hey @feelingnothing, good observations! We have discussed it previously, see

@feelingnothing
Copy link
Author

Hi, looking into this comment I faced the same issue, having to dive into the source code to find the reason on my program not compiling is not a great experience per se, great testing tooling is great to have, until it messes with how you expect a library to work, considering all of the sqlx pool connections are Cloneable. Having a concurrent access to MockDatabase is not a issue at all, considering that no one will actually do tests that way, either way mock is extension and not something to use in production for, so i think it is justifiable to make a changes in favor of production ready code. Another way is to exclude the MockDatabase from DatabaseConnection and let it have a different struct that will not be Cloneable.

@billy1624
Copy link
Member

How about we exclude mock feature from default feature? This way normal user will have cloneable DatabaseConnection out of the box.

@feelingnothing
Copy link
Author

Sound cool, considering that not much people would write tests with sea-orm along the lines, but the main problem is that if person would have to write a test with it, that person would lose Clone, also the fact that it is a breaking change. My point on either making separate MockDatabaseConnection specifically for testing purposes, or making Clone a default for DatabaseConnection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants