diff --git a/src/Database/PostgreSQL.js b/src/Database/PostgreSQL.js index e48d74f..3007fba 100644 --- a/src/Database/PostgreSQL.js +++ b/src/Database/PostgreSQL.js @@ -37,10 +37,10 @@ exports.ffiUnsafeQuery = function(client) { text: sql, values: values, rowMode: 'array', - }).catch(function(err) { - onError(err); }).then(function(result) { onSuccess(result.rows); + }).catch(function(err) { + onError(err); }); return function (cancelError, cancelerError, cancelerSuccess) { diff --git a/test/Main.purs b/test/Main.purs index e89f920..17ff9ec 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -10,6 +10,7 @@ import Data.Array (zip) import Data.Date (Date, canonicalDate) import Data.DateTime.Instant (Instant, unInstant) import Data.Decimal as D +import Data.Either (isLeft) import Data.Enum (toEnum) import Data.Foldable (all, length) import Data.JSDate (JSDate, jsdate, toInstant) @@ -169,6 +170,15 @@ main = void $ launchAff do """) Row0 liftEffect <<< assert $ sauerkrautPrice == [Row1 (D.fromString "3.30")] + test conn "constraint failure" $ do + withTransaction conn $ do + result <- try $ execute conn (Query """ + INSERT INTO foods (name) + VALUES ($1) + """) (Row1 "pork") + liftEffect <<< assert $ isLeft result + testCount 0 + test conn "handling date value" $ do let d1 = date 2010 2 31