on dev help sign in
Merge pull request #20 from echatav/binary
d0486fcEitan Chatav
squeel-postgresql/squeel-postgresql.cabal+1−1
@@ -13,10 +13,10 @@ cabal-version: >=1.10
13library
13library
14 hs-source-dirs: src
14 hs-source-dirs: src
15 exposed-modules:
15 exposed-modules:
16+ Squeel.PostgreSQL.Binary
16 Squeel.PostgreSQL.PQ
17 Squeel.PostgreSQL.PQ
17 Squeel.PostgreSQL.Statement
18 Squeel.PostgreSQL.Statement
18 Squeel.PostgreSQL.Schema
19 Squeel.PostgreSQL.Schema
19− Squeel.PostgreSQL.Value
20 default-language: Haskell2010
20 default-language: Haskell2010
21 ghc-options: -Wall -Werror
21 ghc-options: -Wall -Werror
22 build-depends:
22 build-depends:
squeel-postgresql/src/Squeel/PostgreSQL/Value.hs → squeel-postgresql/src/Squeel/PostgreSQL/Binary.hsrenamed+10−1
@@ -9,7 +9,7 @@
9 , TypeOperators
9 , TypeOperators
10#-}
10#-}
11
11
12−module Squeel.PostgreSQL.Value where
12+module Squeel.PostgreSQL.Binary where
13
13
14import Control.Arrow (left)
14import Control.Arrow (left)
15import Data.Aeson (FromJSON, ToJSON, eitherDecodeStrict, encode)
15import Data.Aeson (FromJSON, ToJSON, eitherDecodeStrict, encode)
@@ -81,6 +81,15 @@ instance FromValue 'PGTimestampTZ UTCTime where
81instance FromValue 'PGInterval DiffTime where
81instance FromValue 'PGInterval DiffTime where
82 fromValue _ = Decoder.interval_int
82 fromValue _ = Decoder.interval_int
83
83
84+class FromValues pgs xs where
85+ decodeValues :: Proxy# pgs -> Rec (Const ByteString) xs -> Rec (Either Text) xs
86+instance FromValues '[] '[] where decodeValues _ _ = RNil
87+instance (FromValue pg x, FromValues pgs xs)
88+ => FromValues (pg ': pgs) (x ': xs) where
89+ decodeValues _ (Const result :& results) =
90+ decodeValue (proxy# :: Proxy# pg) result
91+ :& decodeValues (proxy# :: Proxy# pgs) results
92+
84class ToValue x (pg :: PGType) where
93class ToValue x (pg :: PGType) where
85 toValue :: Proxy# pg -> Encoder x
94 toValue :: Proxy# pg -> Encoder x
86instance ToValue Int16 'PGInt2 where
95instance ToValue Int16 'PGInt2 where
squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+1−1
@@ -28,8 +28,8 @@ import GHC.TypeLits
28
28
29import qualified Database.PostgreSQL.LibPQ as LibPQ
29import qualified Database.PostgreSQL.LibPQ as LibPQ
30
30
31+import Squeel.PostgreSQL.Binary
31import Squeel.PostgreSQL.Statement
32import Squeel.PostgreSQL.Statement
32−import Squeel.PostgreSQL.Value
33import Squeel.PostgreSQL.Schema
33import Squeel.PostgreSQL.Schema
34
34
35newtype Connection db = Connection { unConnection :: LibPQ.Connection }
35newtype Connection db = Connection { unConnection :: LibPQ.Connection }