on dev help sign in
Merge pull request #20 from echatav/binary

Binary

commitd0486fcba6a2a2cbd77516ff818aa305af076108 authorEitan Chatav <eitan.chatav@gmail.com> dateMon 19 Jun 2017, 14:25 (9 years ago) parent871b2a2ce8d909
3 files changed+12−3
squeel-postgresql/squeel-postgresql.cabal+1−1 squeel-postgresql/src/Squeel/PostgreSQL/Value.hs → squeel-postgresql/src/Squeel/PostgreSQL/Binary.hs+10−1 squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+1−1
squeel-postgresql/squeel-postgresql.cabal+1−1
@@ -13,10 +13,10 @@ cabal-version: >=1.10
1313library
1414 hs-source-dirs: src
1515 exposed-modules:
16+ Squeel.PostgreSQL.Binary
1617 Squeel.PostgreSQL.PQ
1718 Squeel.PostgreSQL.Statement
1819 Squeel.PostgreSQL.Schema
19− Squeel.PostgreSQL.Value
2020 default-language: Haskell2010
2121 ghc-options: -Wall -Werror
2222 build-depends:
squeel-postgresql/src/Squeel/PostgreSQL/Value.hs → squeel-postgresql/src/Squeel/PostgreSQL/Binary.hsrenamed+10−1
@@ -9,7 +9,7 @@
99 , TypeOperators
1010#-}
1111
12−module Squeel.PostgreSQL.Value where
12+module Squeel.PostgreSQL.Binary where
1313
1414import Control.Arrow (left)
1515import Data.Aeson (FromJSON, ToJSON, eitherDecodeStrict, encode)
@@ -81,6 +81,15 @@ instance FromValue 'PGTimestampTZ UTCTime where
8181instance FromValue 'PGInterval DiffTime where
8282 fromValue _ = Decoder.interval_int
8383
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+
8493class ToValue x (pg :: PGType) where
8594 toValue :: Proxy# pg -> Encoder x
8695instance ToValue Int16 'PGInt2 where
squeel-postgresql/src/Squeel/PostgreSQL/PQ.hs+1−1
@@ -28,8 +28,8 @@ import GHC.TypeLits
2828
2929import qualified Database.PostgreSQL.LibPQ as LibPQ
3030
31+import Squeel.PostgreSQL.Binary
3132import Squeel.PostgreSQL.Statement
32−import Squeel.PostgreSQL.Value
3333import Squeel.PostgreSQL.Schema
3434
3535newtype Connection db = Connection { unConnection :: LibPQ.Connection }