mirror of
https://github.com/nikita-volkov/hasql.git
synced 2024-12-25 03:01:42 +03:00
Fix #80, better behavior for unknown encoder
This commit is contained in:
parent
7b8b21769e
commit
26fc28d922
@ -28,7 +28,7 @@ run' (Params (Op op)) params integerDatetimes =
|
||||
step (oid, bytesGetter) ~(oidList, bytesAndFormatList) =
|
||||
(,)
|
||||
(oid : oidList)
|
||||
(fmap (\bytes -> (bytes, A.Binary)) (bytesGetter integerDatetimes) : bytesAndFormatList)
|
||||
(fmap (\bytes -> (bytes, format oid)) (bytesGetter integerDatetimes) : bytesAndFormatList)
|
||||
|
||||
run'' :: Params a -> a -> Bool -> [Maybe (A.Oid, ByteString, A.Format)]
|
||||
run'' (Params (Op op)) params integerDatetimes =
|
||||
@ -39,7 +39,12 @@ run'' (Params (Op op)) params integerDatetimes =
|
||||
mapping a : b
|
||||
where
|
||||
mapping (oid, bytesGetter) =
|
||||
(,,) <$> pure oid <*> bytesGetter integerDatetimes <*> pure A.Binary
|
||||
(,,) <$> pure oid <*> bytesGetter integerDatetimes <*> pure (format oid)
|
||||
|
||||
format :: A.Oid -> A.Format
|
||||
format oid = case oid of
|
||||
A.Oid 705 -> A.Text -- is unknown
|
||||
_ -> A.Binary
|
||||
|
||||
value :: C.Value a -> Params a
|
||||
value =
|
||||
|
@ -283,27 +283,27 @@ tree =
|
||||
Query.statement sql mempty Decoders.unit True
|
||||
where
|
||||
sql =
|
||||
"drop type if exists mood"
|
||||
"create or replace function overloaded(a int, b int) returns int as $$ select a + b $$ language sql;"
|
||||
in DSL.query () query
|
||||
let
|
||||
query =
|
||||
Query.statement sql mempty Decoders.unit True
|
||||
where
|
||||
sql =
|
||||
"create type mood as enum ('sad', 'ok', 'happy')"
|
||||
"create or replace function overloaded(a text, b text, c text) returns text as $$ select a || b || c $$ language sql;"
|
||||
in DSL.query () query
|
||||
let
|
||||
query =
|
||||
Query.statement sql encoder decoder True
|
||||
where
|
||||
sql =
|
||||
"select $1 = ('ok' :: mood)"
|
||||
"select overloaded($1, $2) || overloaded($3, $4, $5)"
|
||||
decoder =
|
||||
(Decoders.singleRow (Decoders.value (Decoders.bool)))
|
||||
(Decoders.singleRow (Decoders.value (Decoders.text)))
|
||||
encoder =
|
||||
Encoders.value (Encoders.unknown)
|
||||
in DSL.query "ok" query
|
||||
in actualIO >>= assertEqual "" (Right True)
|
||||
contramany (Encoders.value Encoders.unknown)
|
||||
in DSL.query ["1", "2", "4", "5", "6"] query
|
||||
in actualIO >>= assertEqual "" (Right "3456")
|
||||
,
|
||||
testCase "Enum" $
|
||||
let
|
||||
|
Loading…
Reference in New Issue
Block a user