on dev help sign in
Binary2
6f75a2dEitan Chatav
squeel-postgresql/squeel-postgresql.cabal+1
@@ -15,6 +15,7 @@ library
15 exposed-modules:
15 exposed-modules:
16 Squeel.PostgreSQL
16 Squeel.PostgreSQL
17 Squeel.PostgreSQL.Binary
17 Squeel.PostgreSQL.Binary
18+ Squeel.PostgreSQL.Binary2
18 Squeel.PostgreSQL.PQ
19 Squeel.PostgreSQL.PQ
19 Squeel.PostgreSQL.Statement
20 Squeel.PostgreSQL.Statement
20 Squeel.PostgreSQL.Schema
21 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