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

Support for row locking? #111

Closed
nappa85 opened this issue Aug 27, 2021 · 7 comments · Fixed by #118
Closed

Support for row locking? #111

nappa85 opened this issue Aug 27, 2021 · 7 comments · Fixed by #118

Comments

@nappa85
Copy link
Contributor

nappa85 commented Aug 27, 2021

Hello, it's me again! xD

I just noticed there is no support for row locking (or at least I haven't find out).
Is it something you have excluded for a reason or simply you still haven't covered this feature?

@tyt2y3
Copy link
Member

tyt2y3 commented Aug 27, 2021

Hi there, welcome again )
No, it's just not being thoroughly investigated yet.

@tqwewe
Copy link
Contributor

tqwewe commented Aug 27, 2021

@nappa85 Could you briefly explain what row locking is? I haven't heard of this before. Is this something similar to a read/write mutex but for a row in the database?

@nappa85
Copy link
Contributor Author

nappa85 commented Aug 27, 2021

@nappa85 Could you briefly explain what row locking is? I haven't heard of this before. Is this something similar to a read/write mutex but for a row in the database?

Yeah, sure.
Row locking works only inside a transaction (or at least MySQL is designed like that), you can lock a row in 2 ways:
shared: like a RwLock::read(), done appending "FOR SHARE" at the end of the query;
exclusive: like a RwLock::write(), done appending "FOR UPDATE" at the end of the query;

You can read official docs here: https://dev.mysql.com/doc/refman/8.0/en/innodb-locking.html#innodb-shared-exclusive-locks

From a quick search, I see PostgreSQL has many more lock types: https://www.postgresql.org/docs/9.1/explicit-locking.html

I'm still not familiar with your APIs, but being only an append to a select query I see it as a set of methods of sea_orm::query::Select, aside of the existing one, all and paginate, something like

fn one_lock(self, db: &DatabaseConnection, lock_tipe: LockType) -> Result<Option<E::Model>, DbErr>;
fn all_lock(self, db: &DatabaseConnection, lock_tipe: LockType) -> Result<Vec<E::Model>, DbErr>;
fn paginate_lock(self, db: &DatabaseConnection, page_size: usize, lock_tipe: LockType) -> Paginator<'_, SelectModel<E::Model>>;

@tqwewe
Copy link
Contributor

tqwewe commented Aug 27, 2021

Oh wow okay thats awesome thank you! I can't believe I've never come across MySQL/Postgres row locks before! Seems like a nice feature to have.
Btw I am just a strong user of SeaORM haha not a dev on it for now 😀.

@nappa85
Copy link
Contributor Author

nappa85 commented Sep 5, 2021

I think we can close this issue, since my PR has been merged, right?

@tyt2y3
Copy link
Member

tyt2y3 commented Sep 5, 2021

Well only the SeaQuery PR has been merged and since SeaORM has bumped the dependency, you can use it now.

It depends on whether you want additional convenience by introducing new API in SeaORM.

@nappa85
Copy link
Contributor Author

nappa85 commented Sep 5, 2021

Well only the SeaQuery PR has been merged and since SeaORM has bumped the dependency, you can use it now.

It depends on whether you want additional convenience by introducing new API in SeaORM.

Oh, you're right, it's the sea-query PR that has been merged, not the sea-orm one

@tyt2y3 tyt2y3 linked a pull request Sep 18, 2021 that will close this issue
@tyt2y3 tyt2y3 closed this as completed Sep 18, 2021
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 a pull request may close this issue.

3 participants