on dev help sign in
Binary2
commit6f75a2ddfbed951165ac88d043b1c38292138c7d authorEitan Chatav <eitan.chatav@gmail.com> dateFri 11 Aug 2017, 15:47 (9 years ago) parentc1c65d2
2 files changed+35
squeel-postgresql/squeel-postgresql.cabal+1 squeel-postgresql/src/Squeel/PostgreSQL/Binary2.hs+34
squeel-postgresql/squeel-postgresql.cabal+1
@@ -15,6 +15,7 @@ library
1515 exposed-modules:
1616 Squeel.PostgreSQL
1717 Squeel.PostgreSQL.Binary
18+ Squeel.PostgreSQL.Binary2
1819 Squeel.PostgreSQL.PQ
1920 Squeel.PostgreSQL.Statement
2021 Squeel.PostgreSQL.Schema
squeel-postgresql/src/Squeel/PostgreSQL/Binary2.hsnew file+34
@@ -0,0 +1,34 @@
1+{-# LANGUAGE
2+ DefaultSignatures
3+ , FlexibleContexts
4+ , GADTs
5+ , MultiParamTypeClasses
6+#-}
7+
8+module Squeel.PostgreSQL.Binary2 where
9+
10+import Generics.SOP
11+
12+import qualified PostgreSQL.Binary.Decoding as Decoding
13+import qualified PostgreSQL.Binary.Encoding as Encoding
14+
15+class ToParam x pg where
16+ toParam :: x -> K Encoding.Encoding pg
17+class ToParams x pgs where
18+ toParams :: x -> NP (K Encoding.Encoding) pgs
19+ default toParams
20+ :: (IsProductType x xs, AllZip ToParam xs pgs)
21+ => x -> NP (K Encoding.Encoding) pgs
22+ toParams
23+ = htrans (Proxy :: Proxy ToParam) (toParam . unI) . unZ . unSOP . from
24+
25+class FromValue pg y where
26+ fromValue :: proxy pg -> Decoding.Value y
27+class FromRow pgs y where
28+ fromRow :: NP proxy pgs -> Decoding.Value y
29+ default fromRow
30+ :: (IsProductType y ys, AllZip FromValue pgs ys)
31+ => NP proxy pgs -> Decoding.Value y
32+ fromRow
33+ = fmap to . hsequence
34+ . htrans (Proxy :: Proxy FromValue) fromValue . SOP . Z