Merge pull request #26 from akheron/issue-24

WIP: Avoid `UnhandledPromiseRejectionWarning` on integrity errors
This commit is contained in:
paluh 2018-10-20 20:35:29 +02:00 committed by GitHub
commit 3363bffce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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) {

View File

@ -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