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

MySQL support #10

Merged
merged 1 commit into from Oct 2, 2019
Merged

MySQL support #10

merged 1 commit into from Oct 2, 2019

Conversation

alu
Copy link

@alu alu commented Sep 30, 2019

@ivanceras
Hi.

I love this crate more than diesel but not contains mysql support so i added it.

The big issue

r2d2-mysql wants connection as mutable for execute query but current signature of Database trait expects immutable.
I added Database2, DBPlatform2 and EntityManager2 for keep API for postgres and sqlite.
rust-postgres next varsion will be wanted mutable connection maybe (SEE).

I cloud not implement all of function of Database trait to Database2 trait.
But i think it is enough for SELECT, INSERT, UPDATE and DELETE.
I hope merge this PR and then implement other function in after.

Please tell me if there are mistake in my code or thinking.

Thank you!

@alu
Copy link
Author

alu commented Oct 1, 2019

insert() problem in mysql

mysql does not support RETURNING same as sqlite.
So we have to call insert_simple in insert method.
insert_simple get latest inserted values by LAST_INSERT_ROWID() but it's not supported mysql.

Do you have any good idea for solve the issue?

@ivanceras
Copy link
Owner

mysql has LAST_INSERT_ID() . This is however, not safe when there are multiple records inserting on the same table which can lead to returning the value from other executing queries.

@alu
Copy link
Author

alu commented Oct 1, 2019

I think LAST_INSERT_ID is safety almost caes.

But we have not way to know name of auto increment column for now.
And auto increment column is there not always.

@ivanceras
Copy link
Owner

I just started to work on this on a separate branch. I'll try to merge the support for mysql into a unified Database trait.
Progress will be slow since I will be doing this only on my spare time.

@ivanceras ivanceras merged commit e629ad8 into ivanceras:master Oct 2, 2019
@ivanceras
Copy link
Owner

Gahh... My mistake, I carelessly merged to master and push.
I'm forcing a push to the master from previous commit now.

@alu
Copy link
Author

alu commented Oct 2, 2019

@ivanceras
Thanks.
Could you to create a milestone for mysql support?
I will spend time for mysql support as far as possible.

@ivanceras ivanceras added this to the mysql-support milestone Oct 2, 2019
@ivanceras
Copy link
Owner

So, the database adapters are moving to mutable interfaces.

  • rust-postgres (next version) mutable connection
  • mysql adaptor has been mutable for awhile now (since the first iterations?).
  • sqlite still immutable

Damn, so the next version of the database adaptor is requiring that the connection will have to be mutable.

Since dealing with mutable objects is less flexible, this requires an overhaul of the rustorm core traits and interface.

I may have to keep the 2 interfaces for now. I will rename Database2 to DatabaseMut, EntityManager2 to EntityManagerMut, and then slowly transition to a better mutable interface.

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

Successfully merging this pull request may close these issues.

None yet

2 participants