@@ -1,3 +1,7 @@
1+{-# LANGUAGE
2+ TypeFamilies
3+#-}
4+
15{-|
26Module: Squeal.PostgreSQL.Binary
37Description: Binary encoding and decoding
@@ -200,8 +204,13 @@ True
200204#-}
201205
202206module Squeal.PostgreSQL.Binary
203− ( -- * Encoding
204− ToParam (..)
207+ ( Json (..)
208+ , Jsonb (..)
209+ , Composite (..)
210+ , Enumerated (..)
211+ , VarArray (..)
212+ -- * Encoding
213+ , ToParam (..)
205214 , ToParams (..)
206215 -- * Decoding
207216 , FromValue (..)
@@ -660,3 +669,70 @@ replicateMN
660669 => m x -> m (NP I xs)
661670replicateMN mx = hsequence' $
662671 hcpure (Proxy :: Proxy ((~) x)) (Comp (I <$> mx))
672+
673+{- | The `Json` newtype is an indication that the Haskell
674+type it's applied to should be stored as a `PGjson`.
675+-}
676+newtype Json hask = Json {getJson :: hask}
677+ deriving (Eq, Ord, Show, Read, GHC.Generic)
678+type instance PG (Json hask) = 'PGjson
679+
680+{- | The `Jsonb` newtype is an indication that the Haskell
681+type it's applied to should be stored as a `PGjsonb`.
682+-}
683+newtype Jsonb hask = Jsonb {getJsonb :: hask}
684+ deriving (Eq, Ord, Show, Read, GHC.Generic)
685+type instance PG (Jsonb hask) = 'PGjsonb
686+
687+{- | The `Composite` newtype is an indication that the Haskell
688+type it's applied to should be stored as a `PGcomposite`.
689+-}
690+newtype Composite record = Composite {getComposite :: record}
691+ deriving (Eq, Ord, Show, Read, GHC.Generic)
692+type instance PG (Composite hask) = 'PGcomposite (RowPG hask)
693+
694+{- | The `Enumerated` newtype is an indication that the Haskell
695+type it's applied to should be stored as a `PGenum`.
696+-}
697+newtype Enumerated enum = Enumerated {getEnumerated :: enum}
698+ deriving (Eq, Ord, Show, Read, GHC.Generic)
699+type instance PG (Enumerated hask) = 'PGenum (LabelsPG hask)
700+
701+{- | The `VarArray` newtype is an indication that the Haskell
702+type it's applied to should be stored as a `PGvararray`.
703+-}
704+newtype VarArray arr = VarArray {getVarArray :: arr}
705+ deriving (Eq, Ord, Show, Read, GHC.Generic)
706+type instance PG (VarArray (Vector hask)) = 'PGvararray (NullPG hask)
707+
708+{- | The `FixArray` newtype is an indication that the Haskell
709+type it's applied to should be stored as a `PGfixarray`.
710+-}
711+newtype FixArray arr = FixArray {getFixArray :: arr}
712+ deriving (Eq, Ord, Show, Read, GHC.Generic)
713+-- type instance PG (FixArray x) = 'PGfixarray (DimPG x) (FixPG x)
714+
715+type family DimPG (hask :: Type) :: [Nat] where
716+ DimPG (x,x) = 2 ': DimPG x
717+ DimPG (x,x,x) = 3 ': DimPG x
718+ DimPG (x,x,x,x) = 4 ': DimPG x
719+ DimPG (x,x,x,x,x) = 5 ': DimPG x
720+ DimPG (x,x,x,x,x,x) = 6 ': DimPG x
721+ DimPG (x,x,x,x,x,x,x) = 7 ': DimPG x
722+ DimPG (x,x,x,x,x,x,x,x) = 8 ': DimPG x
723+ DimPG (x,x,x,x,x,x,x,x,x) = 9 ': DimPG x
724+ DimPG (x,x,x,x,x,x,x,x,x,x) = 10 ': DimPG x
725+ DimPG x = '[]
726+
727+type family FixPG (hask :: Type) :: NullityType where
728+ FixPG (x,x) = FixPG x
729+ FixPG (x,x,x) = FixPG x
730+ FixPG (x,x,x,x) = FixPG x
731+ FixPG (x,x,x,x,x) = FixPG x
732+ FixPG (x,x,x,x,x,x) = FixPG x
733+ FixPG (x,x,x,x,x,x,x) = FixPG x
734+ FixPG (x,x,x,x,x,x,x,x) = FixPG x
735+ FixPG (x,x,x,x,x,x,x,x,x) = FixPG x
736+ FixPG (x,x,x,x,x,x,x,x,x,x) = FixPG x
737+ FixPG (x,x,x,x,x,x,x,x,x,x,x) = FixPG x
738+ FixPG x = NullPG x