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

Allow table names with `forUpdate`/`forShare` #2834

Closed
sgoll opened this Issue Oct 2, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@sgoll
Copy link
Contributor

sgoll commented Oct 2, 2018

Environment

Knex version: 0.15.2
Database + version: PostgreSQL 10.5
OS: Linux

Feature discussion / request

I would like to build SELECT … FOR UPDATE (and SELECT … FOR SHARE) queries that only lock some tables from the selection. In particular, this is required for queries that contain nullable outer joins such as LEFT JOIN on nullable columns.

PostgreSQL 9+ supports this with the syntax SELECT … FOR UPDATE OF table_name. See manual, section "FOR UPDATE/FOR SHARE Clause" for details.

The API change I propose would be backwards-compatible by allowing a list of table names in the forUpdate()/forShare() call, e.g.

  • forUpdate('lorem')
  • forUpdate('lorem', 'ipsum')
  • forUpdate(['lorem', 'ipsum'])

(The different variants would match the different ways of specifying columns names in the column() call.)

I'd be willing to prepare a pull request that implements the proposed change.

@sgoll

This comment has been minimized.

Copy link
Contributor

sgoll commented Oct 2, 2018

I went ahead and prepared pull request #2835 that implements the proposed change.

tgriesser added a commit that referenced this issue Oct 4, 2018

Allow table names with forUpdate/forShare (#2834) (#2835)
* Allow table names with forUpdate/forShare (#2834)

* Add integration test for partial table locks

* Simplify code of table name concatenation

* Add changelog entry

@tgriesser tgriesser closed this Oct 4, 2018

@sgoll sgoll referenced this issue Oct 4, 2018

Closed

Added initial knex@next types #29256

8 of 9 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment