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 more locking kind #333

Closed

Conversation

josephsumabat
Copy link
Contributor

@josephsumabat josephsumabat commented Aug 19, 2022

Context:
Support FOR UPDATE Of tablename SKIP LOCKED syntax:

Going to look at adding FOR x OF [tables] syntax to the rest of the locking kinds hence making this a draft (Plus updating to use the (_ &: _) esqueleto style instead of an existential type

This allows a the FOR UPDATE SKIP LOCKED behaviour when you have a LEFT OUTER JOIN with a nullable side. Currently you will get the error:

FOR UPDATE cannot be applied to the nullable side of an outer join

The workaround currently using esqueleto is to do seperate queries and then join them manually if you want to select rows for an update while skipping locked rows (or to just do a raw query). I ran into this situation at work.

See: https://www.postgresql.org/docs/current/sql-select.html
namely:

FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE } [ OF table_name [, ...] ] [ NOWAIT | SKIP LOCKED ] [...] ]

also documented in MySQL:
https://dev.mysql.com/doc/refman/8.0/en/select.html

    [FOR {UPDATE | SHARE}
        [OF tbl_name [, tbl_name] ...]
        [NOWAIT | SKIP LOCKED]
      | LOCK IN SHARE MODE]
    [into_option]

Usage example would be

select $ do
    (p :& bp) <- from $ 
        table @Person
        `innerJoin` table @BlogPost
            `on` do
                \(p :& b) -> p ^. PersonId ==. b ^. BlogPostAuthorId
                EP.forUpdateOf (p :& b) EP.skipLocked
    return p

After submitting your PR:

  • Update the Changelog.md file with a link to your PR.
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts).


-- | Wraps table type entities for use with LockingKind.
data PostgresLockingKind where
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Introduces this new type used only internally

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.

1 participant