@@ -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