Skip to content

Commit

Permalink
Fix Postgres syntax for NOWAIT (#377)
Browse files Browse the repository at this point in the history
* Fix Postgres syntax for NOWAIT

* Add noWait test for PostgreSQL

* Bump version
  • Loading branch information
ttuegel authored Sep 7, 2023
1 parent e50fed1 commit d805bb0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
3.5.10.3
========
- @ttuegel
- [#377](https://github.com/bitemyapp/esqueleto/pull/377)
- Fix Postgres syntax for `noWait`

3.5.10.2
========
- @parsonsmatt
Expand Down
2 changes: 1 addition & 1 deletion esqueleto.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cabal-version: 1.12

name: esqueleto

version: 3.5.10.2
version: 3.5.10.3
synopsis: Type-safe EDSL for SQL queries on persistent backends.
description: @esqueleto@ is a bare bones, type-safe EDSL for SQL queries that works with unmodified @persistent@ SQL backends. Its language closely resembles SQL, so you don't have to learn new concepts, just new syntax, and it's fairly easy to predict the generated SQL and optimize it for your backend. Most kinds of errors committed when writing SQL are caught as compile-time errors---although it is possible to write type-checked @esqueleto@ queries that fail at runtime.
.
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Esqueleto/Internal/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3257,7 +3257,7 @@ makeLocking info (PostgresLockingClauses clauses) =
makeLockingStrength PostgresForShare = plain "FOR SHARE"

makeLockingBehavior :: OnLockedBehavior -> (TLB.Builder, [PersistValue])
makeLockingBehavior NoWait = plain "NO WAIT"
makeLockingBehavior NoWait = plain "NOWAIT"
makeLockingBehavior SkipLocked = plain "SKIP LOCKED"
makeLockingBehavior Wait = plain ""

Expand Down
2 changes: 1 addition & 1 deletion src/Database/Esqueleto/PostgreSQL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ values exprs = Ex.From $ do
, params
)

-- | `NO WAIT` syntax for postgres locking
-- | `NOWAIT` syntax for postgres locking
-- error will be thrown if locked rows are attempted to be selected
--
-- @since 3.5.9.0
Expand Down
9 changes: 9 additions & 0 deletions test/PostgreSQL/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,15 @@ testPostgresqlLocking = do
asserting sideThreadAsserts
asserting $ length nonLockedRowsAfterUpdate `shouldBe` 3

describe "noWait" $ do
itDb "doesn't crash" $ do
select $ do
t <- Experimental.from $ table @Person
EP.forUpdateOf t EP.noWait
pure t

asserting noExceptions

-- Since lateral queries arent supported in Sqlite or older versions of mysql
-- the test is in the Postgres module
testLateralQuery :: SpecDb
Expand Down

0 comments on commit d805bb0

Please sign in to comment.