on dev help sign in
docs for Binary
64b6296Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+19−3
@@ -205,12 +205,14 @@ module Squeal.PostgreSQL.Binary
205 ( -- * Encoding
205 ( -- * Encoding
206 ToParam (..)
206 ToParam (..)
207 , ToParams (..)
207 , ToParams (..)
208− , ToNullityParam
208+ , ToNullityParam (..)
209− , ToField
209+ , ToField (..)
210− , ToFixArray
210+ , ToFixArray (..)
211 -- * Decoding
211 -- * Decoding
212 , FromValue (..)
212 , FromValue (..)
213 , FromRow (..)
213 , FromRow (..)
214+ , FromField (..)
215+ , FromFixArray (..)
214 -- * Only
216 -- * Only
215 , Only (..)
217 , Only (..)
216 ) where
218 ) where
@@ -394,6 +396,8 @@ class HasAliasedOid (field :: (Symbol, NullityType)) where
394instance HasOid ty => HasAliasedOid (alias ::: nullity ty) where
396instance HasOid ty => HasAliasedOid (alias ::: nullity ty) where
395 aliasedOid = oid @ty
397 aliasedOid = oid @ty
396
398
399+-- | A `ToNullityParam` constraint gives an encoding of a Haskell `Type` into
400+-- into the binary format of a PostgreSQL `NullityType`.
397class ToNullityParam (x :: Type) (ty :: NullityType) where
401class ToNullityParam (x :: Type) (ty :: NullityType) where
398 toNullityParam :: x -> K (Maybe Encoding.Encoding) ty
402 toNullityParam :: x -> K (Maybe Encoding.Encoding) ty
399instance ToParam x pg => ToNullityParam x ('NotNull pg) where
403instance ToParam x pg => ToNullityParam x ('NotNull pg) where
@@ -401,11 +405,19 @@ instance ToParam x pg => ToNullityParam x ('NotNull pg) where
401instance ToParam x pg => ToNullityParam (Maybe x) ('Null pg) where
405instance ToParam x pg => ToNullityParam (Maybe x) ('Null pg) where
402 toNullityParam = K . fmap (unK . toParam @x @pg)
406 toNullityParam = K . fmap (unK . toParam @x @pg)
403
407
408+-- | A `ToField` constraint lifts the `ToParam` parser
409+-- to an encoding of a @(Symbol, Type)@ to a @(Symbol, NullityType)@,
410+-- encoding `Null`s to `Maybe`s. You should not define instances for
411+-- `FromField`, just use the provided instances.
404class ToField (x :: (Symbol, Type)) (field :: (Symbol, NullityType)) where
412class ToField (x :: (Symbol, Type)) (field :: (Symbol, NullityType)) where
405 toField :: P x -> K (Maybe Encoding.Encoding) field
413 toField :: P x -> K (Maybe Encoding.Encoding) field
406instance ToNullityParam x ty => ToField (alias ::: x) (alias ::: ty) where
414instance ToNullityParam x ty => ToField (alias ::: x) (alias ::: ty) where
407 toField (P x) = K . unK $ toNullityParam @x @ty x
415 toField (P x) = K . unK $ toNullityParam @x @ty x
408
416
417+-- | A `ToFixArray` constraint gives an encoding of a Haskell `Type`
418+-- into the binary format of a PostgreSQL fixed-length array.
419+-- You should not define instances for
420+-- `ToFixArray`, just use the provided instances.
409class ToFixArray (x :: Type) (dims :: [Nat]) (array :: NullityType) where
421class ToFixArray (x :: Type) (dims :: [Nat]) (array :: NullityType) where
410 toFixArray :: x -> K (K Encoding.Array dims) array
422 toFixArray :: x -> K (K Encoding.Array dims) array
411instance ToNullityParam x ty => ToFixArray x '[] ty where
423instance ToNullityParam x ty => ToFixArray x '[] ty where
@@ -589,6 +601,10 @@ instance FromValue pg y
589 K (Just bytestring) -> P . Just <$>
601 K (Just bytestring) -> P . Just <$>
590 Decoding.valueParser (fromValue @pg) bytestring
602 Decoding.valueParser (fromValue @pg) bytestring
591
603
604+-- | A `FromFixArray` constraint gives a decoding to a Haskell `Type`
605+-- from the binary format of a PostgreSQL fixed-length array.
606+-- You should not define instances for
607+-- `FromFixArray`, just use the provided instances.
592class FromFixArray (dims :: [Nat]) (ty :: NullityType) (y :: Type) where
608class FromFixArray (dims :: [Nat]) (ty :: NullityType) (y :: Type) where
593 fromFixArray :: Decoding.Array y
609 fromFixArray :: Decoding.Array y
594instance FromValue pg y => FromFixArray '[] ('NotNull pg) y where
610instance FromValue pg y => FromFixArray '[] ('NotNull pg) y where
squeal-postgresql/src/Squeal/PostgreSQL/PG.hs+1−1
@@ -167,7 +167,7 @@ type family LabelsPG (hask :: Type) :: [Type.ConstructorName] where
167`RowPG` turns a Haskell `Type` into a `RowType`.
167`RowPG` turns a Haskell `Type` into a `RowType`.
168
168
169`RowPG` may be applied to normal Haskell record types provided they
169`RowPG` may be applied to normal Haskell record types provided they
170−have the `SOP.Generic` and `SOP.HasDatatypeInfo` instances;
170+have `SOP.Generic` and `SOP.HasDatatypeInfo` instances;
171
171
172>>> data Person = Person { name :: Strict.Text, age :: Int32 } deriving GHC.Generic
172>>> data Person = Person { name :: Strict.Text, age :: Int32 } deriving GHC.Generic
173>>> instance SOP.Generic Person
173>>> instance SOP.Generic Person