Skip to content

Ignore FOR UPDATE and FOR SHARE clause#20

Merged
jinzhu merged 1 commit intogo-gorm:masterfrom
c-bata:ignore-rowlevel-locking
Oct 29, 2020
Merged

Ignore FOR UPDATE and FOR SHARE clause#20
jinzhu merged 1 commit intogo-gorm:masterfrom
c-bata:ignore-rowlevel-locking

Conversation

@c-bata
Copy link
Copy Markdown
Contributor

@c-bata c-bata commented Oct 29, 2020

What did this pull request do?

This PR is for automatically skipping FOR UPDATE (and FOR SHARE) clause.

See go-gorm/gorm#3687 for details.

User Case Description

Currently, it is required to write following code:

if s.db.Dialector.Name() == "sqlite" {
	result = tx.First(&study, "study_id = ?", studyID)
} else {
	result = tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&study, "study_id = ?", studyID)
}

https://github.com/c-bata/goptuna/blob/9e9699a4394bf94f2a311ba4574a507ac833c824/rdb.v2/storage.go#L216-L224

From this patch, we can write it like below:

result = tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&study, "study_id = ?", studyID)

@jinzhu jinzhu merged commit e1caf37 into go-gorm:master Oct 29, 2020
@c-bata c-bata deleted the ignore-rowlevel-locking branch October 29, 2020 04:08
@c-bata
Copy link
Copy Markdown
Contributor Author

c-bata commented Oct 29, 2020

@jinzhu Hi, thank you for merging this. Do you have a plan to release v1.1.4 tag?

@jinzhu
Copy link
Copy Markdown
Member

jinzhu commented Oct 29, 2020

Maybe a release after fixed this issue go-gorm/gorm#3585

I think this might need to rewrite the Where clause's builder

@c-bata
Copy link
Copy Markdown
Contributor Author

c-bata commented Oct 29, 2020

I see. Thank you!

samuelncui pushed a commit to samuelncui/gorm-sqlite that referenced this pull request Oct 4, 2023
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.

2 participants