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

Add support for "FOR UPDATE" and "SKIP LOCKED" #62

Merged
merged 4 commits into from
Jun 7, 2019

Conversation

btubbs
Copy link
Contributor

@btubbs btubbs commented Jul 9, 2018

This addresses #43. It's a first stab, but hopefully close.

The public interface only exposes a .ForUpdate() method on the dataset for now, but under the hood it's built to support .ForNoKeyUpdate(), .ForShare(), and .ForKeyShare() as well.

@btubbs
Copy link
Contributor Author

btubbs commented Jul 9, 2018

Let me know if you like this direction, and I'll flesh out tests and the other ForSomething methods.

@btubbs
Copy link
Contributor Author

btubbs commented Jul 9, 2018

Oh and this doesn't yet support the "OF table_name" optional bit of a FOR clause.

default_limit_fragment = []byte(" LIMIT ")
default_offset_fragment = []byte(" OFFSET ")
default_for_update_fragment = []byte(" FOR UPDATE ")
default_for_no_key_update_fragment = []byte(" FOR NO KEY UPDATE ")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem universally supported. Does a downstream user just override this if their rdbms uses different syntax?

Copy link
Contributor Author

@btubbs btubbs Jul 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. Mysql and Postgres both support it. The only other DB in goqu's adapters folder is sqlite3, which lacks lots of stuff the others support.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it's an opt-in feature. If you write a query using it and your DB doesn't support it, you'll just get an error when trying to run the query. You'll then just have to rewrite your query to not use the feature that your DB doesn't support.

@codecov
Copy link

codecov bot commented Jul 9, 2018

Codecov Report

Merging #62 into master will decrease coverage by 0.78%.
The diff coverage is 34.28%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #62      +/-   ##
=========================================
- Coverage   82.98%   82.2%   -0.79%     
=========================================
  Files          17      17              
  Lines        2087    2119      +32     
=========================================
+ Hits         1732    1742      +10     
- Misses        247     268      +21     
- Partials      108     109       +1
Impacted Files Coverage Δ
adapters.go 100% <ø> (ø) ⬆️
dataset.go 95.48% <ø> (ø) ⬆️
dataset_select.go 83.88% <11.11%> (-3.31%) ⬇️
default_adapter.go 80.56% <41.66%> (-1.71%) ⬇️
expressions.go 75.04% <50%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd495d7...bc09683. Read the comment docs.

@doug-martin
Copy link
Owner

@btubbs this looks good if you want to go ahead and add tests for the base adapter and the implemented adapters I can get this merged and released

@btubbs
Copy link
Contributor Author

btubbs commented Sep 12, 2018

Cool. I'll try to get that out this week.

@btubbs
Copy link
Contributor Author

btubbs commented Sep 17, 2018

I added the other methods, and tests.

@arbrix
Copy link

arbrix commented Nov 7, 2018

@doug-martin could you please merge this feature, our project also depend on it

@arbrix
Copy link

arbrix commented Dec 27, 2018

@btubbs could you please tag your branch, this is allowed to use it at replace at go mod while this changes will be merged with the master.

@btubbs
Copy link
Contributor Author

btubbs commented Dec 28, 2018

@arbrix I added the "for-update" tag. Will that work?

@doug-martin doug-martin merged commit 8d01790 into doug-martin:master Jun 7, 2019
doug-martin added a commit that referenced this pull request Jun 7, 2019
* Updated go support to `1.10`, `1.11` and `1.12`
* Change testify dependency from c2fo/testify back to stretchr/testify.
* Add support for "FOR UPDATE" and "SKIP LOCKED" [#62](#62) - [@btubbs](https://github.com/btubbs)
* Changed to use go modules
@doug-martin doug-martin mentioned this pull request Jun 7, 2019
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

4 participants