generated from tpl/purs
feat: int8 support
This commit is contained in:
@@ -23,7 +23,7 @@ import Data.Newtype (unwrap)
|
||||
import Data.Number ((%))
|
||||
import Data.Tuple (Tuple(..))
|
||||
import Data.Tuple.Nested ((/\))
|
||||
import Database.PostgreSQL (Client, Configuration, Connection(..), PGConnectionURI, PGError(..), Pool, Query(Query), Row0(Row0), Row1(Row1), Row2(Row2), Row3(Row3), Row9(Row9), fromClient, fromPool, parseURI)
|
||||
import Database.PostgreSQL (Client, Configuration, Connection(..), PGConnectionURI, PGError(..), Pool, Query(Query), Row0(Row0), Row1(Row1), Row12(..), Row2(Row2), Row3(Row3), Row9(Row9), fromClient, fromPool, parseURI)
|
||||
import Database.PostgreSQL.PG (command, execute, onIntegrityError, query, scalar)
|
||||
import Database.PostgreSQL.PG (withClient, withClientTransaction) as PG
|
||||
import Database.PostgreSQL.Pool (new) as Pool
|
||||
@@ -34,6 +34,8 @@ import Effect.Class (liftEffect)
|
||||
import Effect.Exception (message)
|
||||
import Foreign.Object (Object)
|
||||
import Foreign.Object (fromFoldable) as Object
|
||||
import JS.BigInt (BigInt)
|
||||
import JS.BigInt as BigInt
|
||||
import JS.Unsafe.Stringify (unsafeStringify)
|
||||
import Partial.Unsafe (unsafePartial)
|
||||
import Test.Assert (assert)
|
||||
@@ -45,6 +47,9 @@ import Test.Unit as Test.Unit
|
||||
import Test.Unit.Assert (equal)
|
||||
import Test.Unit.Main (runTest)
|
||||
|
||||
bigintFromString :: String -> BigInt
|
||||
bigintFromString = unsafePartial fromJust <<< BigInt.fromString
|
||||
|
||||
withClient :: forall a. Pool -> (Client -> AppM a) -> AppM a
|
||||
withClient = PG.withClient runExceptT
|
||||
|
||||
@@ -124,6 +129,7 @@ main = do
|
||||
delicious boolean NOT NULL,
|
||||
price NUMERIC(4,2) NOT NULL,
|
||||
added TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
huge_number INT8 NULL,
|
||||
PRIMARY KEY (name)
|
||||
);
|
||||
CREATE TEMPORARY TABLE dates (
|
||||
@@ -263,20 +269,23 @@ main = do
|
||||
execute handle
|
||||
( Query
|
||||
"""
|
||||
INSERT INTO foods (name, delicious, price)
|
||||
VALUES ($1, $2, $3), ($4, $5, $6), ($7, $8, $9)
|
||||
INSERT INTO foods (name, delicious, price, huge_number)
|
||||
VALUES ($1, $2, $3, $4), ($5, $6, $7, $8), ($9, $10, $11, $12)
|
||||
"""
|
||||
)
|
||||
( Row9
|
||||
( Row12
|
||||
"pork"
|
||||
true
|
||||
(D.fromString "8.30")
|
||||
(bigintFromString "123")
|
||||
"sauerkraut"
|
||||
false
|
||||
(D.fromString "3.30")
|
||||
(bigintFromString "456")
|
||||
"rookworst"
|
||||
true
|
||||
(D.fromString "5.60")
|
||||
(bigintFromString "789")
|
||||
)
|
||||
test handle "select column subset"
|
||||
$ do
|
||||
@@ -358,6 +367,20 @@ main = do
|
||||
)
|
||||
Row0
|
||||
liftEffect <<< assert $ sauerkrautPrice == [ Row1 (D.fromString "3.30") ]
|
||||
test handle "handling bigint value"
|
||||
$ do
|
||||
insertFood
|
||||
hugeNumber <-
|
||||
query handle
|
||||
( Query
|
||||
"""
|
||||
SELECT huge_number
|
||||
FROM foods
|
||||
WHERE NOT delicious
|
||||
"""
|
||||
)
|
||||
Row0
|
||||
liftEffect <<< assert $ hugeNumber == [ Row1 (bigintFromString "456") ]
|
||||
transactionTest "integrity error handling"
|
||||
$ do
|
||||
withRollback client do
|
||||
|
||||
Reference in New Issue
Block a user