From f7dc7cef13c0ca586293745786a6b631ddc5edb5 Mon Sep 17 00:00:00 2001 From: Thiago Rodrigues de Paula Date: Mon, 29 Oct 2018 22:59:41 +0100 Subject: [PATCH 1/3] Add ForUpdateSkipLocked to locks --- src/Database/Esqueleto/Internal/Language.hs | 5 +++++ src/Database/Esqueleto/Internal/Sql.hs | 7 ++++--- stack-8.4.yaml | 2 +- test/Common/Test.hs | 7 ++++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Database/Esqueleto/Internal/Language.hs b/src/Database/Esqueleto/Internal/Language.hs index b8d98d5..ac992e1 100644 --- a/src/Database/Esqueleto/Internal/Language.hs +++ b/src/Database/Esqueleto/Internal/Language.hs @@ -829,6 +829,11 @@ data LockingKind = -- PostgreSQL. -- -- /Since: 2.2.7/ + | ForUpdateSkipLocked + -- ^ @FOR UPDATE SKIP LOCKED@ syntax. Supported by MySQL, Oracle and + -- PostgreSQL. + -- + -- /Since: 2.2.7/ | ForShare -- ^ @FOR SHARE@ syntax. Supported by PostgreSQL. -- diff --git a/src/Database/Esqueleto/Internal/Sql.hs b/src/Database/Esqueleto/Internal/Sql.hs index e13877a..16a24e9 100644 --- a/src/Database/Esqueleto/Internal/Sql.hs +++ b/src/Database/Esqueleto/Internal/Sql.hs @@ -1212,9 +1212,10 @@ makeLimit (conn, _) (Limit ml mo) orderByClauses = makeLocking :: LockingClause -> (TLB.Builder, [PersistValue]) makeLocking = flip (,) [] . maybe mempty toTLB . Monoid.getLast where - toTLB ForUpdate = "\nFOR UPDATE" - toTLB ForShare = "\nFOR SHARE" - toTLB LockInShareMode = "\nLOCK IN SHARE MODE" + toTLB ForUpdate = "\nFOR UPDATE" + toTLB ForUpdateSkipLocked = "\nFOR UPDATE SKIP LOCKED" + toTLB ForShare = "\nFOR SHARE" + toTLB LockInShareMode = "\nLOCK IN SHARE MODE" diff --git a/stack-8.4.yaml b/stack-8.4.yaml index 7bbfbb3..05e9eae 100644 --- a/stack-8.4.yaml +++ b/stack-8.4.yaml @@ -5,5 +5,5 @@ packages: extra-deps: - persistent-postgresql-2.8.2.0 -- postgresql-simple-0.5.3.0 +- postgresql-simple-0.5.4.0 allow-newer: true diff --git a/test/Common/Test.hs b/test/Common/Test.hs index 06e8426..fac1135 100644 --- a/test/Common/Test.hs +++ b/test/Common/Test.hs @@ -1333,9 +1333,10 @@ testLocking withConn = do let expected = complex <> "\n" <> syntax (with1, with2, with3) `shouldBe` (expected, expected, expected) - it "looks sane for ForUpdate" $ sanityCheck ForUpdate "FOR UPDATE" - it "looks sane for ForShare" $ sanityCheck ForShare "FOR SHARE" - it "looks sane for LockInShareMode" $ sanityCheck LockInShareMode "LOCK IN SHARE MODE" + it "looks sane for ForUpdate" $ sanityCheck ForUpdate "FOR UPDATE" + it "looks sane for ForUpdateSkipLocked" $ sanityCheck ForUpdateSkipLocked "FOR UPDATE SKIP LOCKED" + it "looks sane for ForShare" $ sanityCheck ForShare "FOR SHARE" + it "looks sane for LockInShareMode" $ sanityCheck LockInShareMode "LOCK IN SHARE MODE" From 78cc8dd508845a29e5ca3f194b679eb082ff2b9c Mon Sep 17 00:00:00 2001 From: Thiago Rodrigues de Paula Date: Mon, 29 Oct 2018 23:37:31 +0100 Subject: [PATCH 2/3] Fix travis mysql tests --- test/MySQL/Test.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/MySQL/Test.hs b/test/MySQL/Test.hs index 1aa6356..0b3a53c 100644 --- a/test/MySQL/Test.hs +++ b/test/MySQL/Test.hs @@ -212,7 +212,7 @@ withConn = R.runResourceT . withMySQLConn defaultConnectInfo { connectHost = "localhost" - , connectUser = "esqutest" - , connectPassword = "esqutest" + , connectUser = "travis" + , connectPassword = "" , connectDatabase = "esqutest" } From a9678c948bdc8d2af702b56bb15f94af05e9d22a Mon Sep 17 00:00:00 2001 From: Thiago Rodrigues de Paula Date: Tue, 30 Oct 2018 00:11:16 +0100 Subject: [PATCH 3/3] Create MySQL db on travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f72133b..4f49567 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,7 @@ install: - stack --version - echo "CREATE USER esqutest WITH PASSWORD 'esqutest';" | psql postgres - createdb -O esqutest esqutest + - mysql -e 'CREATE DATABASE esqutest;' script: - stack setup