on dev help sign in
docs for Binary
commit64b6296d70609208bbbba6751ccac28fb24b82f0 authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateFri 12 Apr 2019, 17:07 (8 years ago) parente20acfb
2 files changed+20−4
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+19−3 squeal-postgresql/src/Squeal/PostgreSQL/PG.hs+1−1
squeal-postgresql/src/Squeal/PostgreSQL/Binary.hs+19−3
@@ -205,12 +205,14 @@ module Squeal.PostgreSQL.Binary
205205 ( -- * Encoding
206206 ToParam (..)
207207 , ToParams (..)
208− , ToNullityParam
209− , ToField
210− , ToFixArray
208+ , ToNullityParam (..)
209+ , ToField (..)
210+ , ToFixArray (..)
211211 -- * Decoding
212212 , FromValue (..)
213213 , FromRow (..)
214+ , FromField (..)
215+ , FromFixArray (..)
214216 -- * Only
215217 , Only (..)
216218 ) where
@@ -394,6 +396,8 @@ class HasAliasedOid (field :: (Symbol, NullityType)) where
394396instance HasOid ty => HasAliasedOid (alias ::: nullity ty) where
395397 aliasedOid = oid @ty
396398
399+-- | A `ToNullityParam` constraint gives an encoding of a Haskell `Type` into
400+-- into the binary format of a PostgreSQL `NullityType`.
397401class ToNullityParam (x :: Type) (ty :: NullityType) where
398402 toNullityParam :: x -> K (Maybe Encoding.Encoding) ty
399403instance ToParam x pg => ToNullityParam x ('NotNull pg) where
@@ -401,11 +405,19 @@ instance ToParam x pg => ToNullityParam x ('NotNull pg) where
401405instance ToParam x pg => ToNullityParam (Maybe x) ('Null pg) where
402406 toNullityParam = K . fmap (unK . toParam @x @pg)
403407
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.
404412class ToField (x :: (Symbol, Type)) (field :: (Symbol, NullityType)) where
405413 toField :: P x -> K (Maybe Encoding.Encoding) field
406414instance ToNullityParam x ty => ToField (alias ::: x) (alias ::: ty) where
407415 toField (P x) = K . unK $ toNullityParam @x @ty x
408416
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.
409421class ToFixArray (x :: Type) (dims :: [Nat]) (array :: NullityType) where
410422 toFixArray :: x -> K (K Encoding.Array dims) array
411423instance ToNullityParam x ty => ToFixArray x '[] ty where
@@ -589,6 +601,10 @@ instance FromValue pg y
589601 K (Just bytestring) -> P . Just <$>
590602 Decoding.valueParser (fromValue @pg) bytestring
591603
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.
592608class FromFixArray (dims :: [Nat]) (ty :: NullityType) (y :: Type) where
593609 fromFixArray :: Decoding.Array y
594610instance 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
167167`RowPG` turns a Haskell `Type` into a `RowType`.
168168
169169`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;
171171
172172>>> data Person = Person { name :: Strict.Text, age :: Int32 } deriving GHC.Generic
173173>>> instance SOP.Generic Person