@@ -100,15 +100,13 @@ module Squeal.PostgreSQL.Schema
100 , PGlabel (..)
100 , PGlabel (..)
101 , renderLabel
101 , renderLabel
102 , renderLabels
102 , renderLabels
105 -- * Embedding
103 -- * Embedding
107− , EnumWith
105+ , EnumFrom
108− , LabelsWith
106+ , LabelsFrom
109− , CompositeWith
107+ , CompositeFrom
110− , FieldNamesWith
108+ , FieldNamesFrom
111− , FieldTypesWith
109+ , FieldTypesFrom
112 , ConstructorsOf
110 , ConstructorsOf
113 , ConstructorNameOf
111 , ConstructorNameOf
114 , ConstructorNamesOf
112 , ConstructorNamesOf
@@ -682,13 +680,6 @@ renderLabels
682 :: All KnownSymbol labels => NP PGlabel labels -> [ByteString]
680 :: All KnownSymbol labels => NP PGlabel labels -> [ByteString]
683renderLabels = hcollapse
681renderLabels = hcollapse
684 . hcmap (Proxy @KnownSymbol) (K . renderLabel)
682 . hcmap (Proxy @KnownSymbol) (K . renderLabel)
685−-- | Gets the name of a type constructor
686−type family LabelOf (cons :: Type.ConstructorInfo) :: Symbol where
687− LabelOf ('Type.Constructor name) = name
688−-- | Gets the names of a list of type constructors
689−type family LabelsOf (conss :: [Type.ConstructorInfo]) :: [Symbol] where
691− LabelsOf (cons ': conss) = LabelOf cons ': LabelsOf conss
693-- | The `PG` type family embeds a subset of Haskell types
684-- | The `PG` type family embeds a subset of Haskell types
694-- as Postgres basic types.
685-- as Postgres basic types.
@@ -724,32 +715,32 @@ type family PG (hask :: Type) :: PGType where
724 PG ty = TypeError
715 PG ty = TypeError
725 ('Text "There is no Postgres basic type for " ':<>: 'ShowType ty)
716 ('Text "There is no Postgres basic type for " ':<>: 'ShowType ty)
727−-- | The `EnumWith` type family embeds Haskell enum types, ADTs with
718+-- | The `EnumFrom` type family embeds Haskell enum types, ADTs with
728-- nullary constructors, as Postgres enum types
719-- nullary constructors, as Postgres enum types
730-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
721-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
731-- >>> instance Generic Schwarma
722-- >>> instance Generic Schwarma
732-- >>> instance HasDatatypeInfo Schwarma
723-- >>> instance HasDatatypeInfo Schwarma
733−-- >>> :kind! EnumWith Schwarma
724+-- >>> :kind! EnumFrom Schwarma
734−-- EnumWith Schwarma :: PGType
725+-- EnumFrom Schwarma :: PGType
735-- = 'PGenum '["Beef", "Lamb", "Chicken"]
726-- = 'PGenum '["Beef", "Lamb", "Chicken"]
736−type family EnumWith (hask :: Type) :: PGType where
727+type family EnumFrom (hask :: Type) :: PGType where
737− EnumWith hask = 'PGenum (LabelsWith hask)
728+ EnumFrom hask = 'PGenum (LabelsFrom hask)
739−-- | The `LabelsWith` type family calculates the constructors of a
730+-- | The `LabelsFrom` type family calculates the constructors of a
740-- Haskell enum type.
731-- Haskell enum type.
742-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
733-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
743-- >>> instance Generic Schwarma
734-- >>> instance Generic Schwarma
744-- >>> instance HasDatatypeInfo Schwarma
735-- >>> instance HasDatatypeInfo Schwarma
745−-- >>> :kind! LabelsWith Schwarma
736+-- >>> :kind! LabelsFrom Schwarma
746−-- LabelsWith Schwarma :: [Type.ConstructorName]
737+-- LabelsFrom Schwarma :: [Type.ConstructorName]
747-- = '["Beef", "Lamb", "Chicken"]
738-- = '["Beef", "Lamb", "Chicken"]
748−type family LabelsWith (hask :: Type) :: [Type.ConstructorName] where
739+type family LabelsFrom (hask :: Type) :: [Type.ConstructorName] where
749− LabelsWith hask =
740+ LabelsFrom hask =
750 ConstructorNamesOf (ConstructorsOf (DatatypeInfoOf hask))
741 ConstructorNamesOf (ConstructorsOf (DatatypeInfoOf hask))
752−-- | The `CompositeWith` type family embeds Haskell record types as
743+-- | The `CompositeFrom` type family embeds Haskell record types as
753-- Postgres composite types, as long as the record fields
744-- Postgres composite types, as long as the record fields
754-- are `Maybe`s of Haskell types that can be embedded as basic types
745-- are `Maybe`s of Haskell types that can be embedded as basic types
755-- with the `PG` type family.
746-- with the `PG` type family.
@@ -757,30 +748,30 @@ type family LabelsWith (hask :: Type) :: [Type.ConstructorName] where
757-- >>> data Row = Row { a :: Maybe Int16, b :: Maybe LocalTime } deriving GHC.Generic
748-- >>> data Row = Row { a :: Maybe Int16, b :: Maybe LocalTime } deriving GHC.Generic
758-- >>> instance Generic Row
749-- >>> instance Generic Row
759-- >>> instance HasDatatypeInfo Row
750-- >>> instance HasDatatypeInfo Row
760−-- >>> :kind! CompositeWith Row
751+-- >>> :kind! CompositeFrom Row
761−-- CompositeWith Row :: PGType
752+-- CompositeFrom Row :: PGType
762-- = 'PGcomposite '['("a", 'PGint2), '("b", 'PGtimestamp)]
753-- = 'PGcomposite '['("a", 'PGint2), '("b", 'PGtimestamp)]
763−type family CompositeWith (hask :: Type) :: PGType where
754+type family CompositeFrom (hask :: Type) :: PGType where
764− CompositeWith hask =
755+ CompositeFrom hask =
765− 'PGcomposite (ZipAs (FieldNamesWith hask) (FieldTypesWith hask))
756+ 'PGcomposite (ZipAs (FieldNamesFrom hask) (FieldTypesFrom hask))
767-- | >>> data Row = Row { a :: Maybe Int16, b :: Maybe LocalTime } deriving GHC.Generic
758-- | >>> data Row = Row { a :: Maybe Int16, b :: Maybe LocalTime } deriving GHC.Generic
768-- >>> instance Generic Row
759-- >>> instance Generic Row
769-- >>> instance HasDatatypeInfo Row
760-- >>> instance HasDatatypeInfo Row
770−-- >>> :kind! FieldNamesWith Row
761+-- >>> :kind! FieldNamesFrom Row
771−-- FieldNamesWith Row :: [Type.FieldName]
762+-- FieldNamesFrom Row :: [Type.FieldName]
772-- = '["a", "b"]
763-- = '["a", "b"]
773−type family FieldNamesWith (hask :: Type) :: [Type.FieldName] where
764+type family FieldNamesFrom (hask :: Type) :: [Type.FieldName] where
774− FieldNamesWith hask = FieldNamesOf (FieldsOf (DatatypeInfoOf hask))
765+ FieldNamesFrom hask = FieldNamesOf (FieldsOf (DatatypeInfoOf hask))
776-- | >>> data Row = Row { a :: Maybe Int16, b :: Maybe LocalTime } deriving GHC.Generic
767-- | >>> data Row = Row { a :: Maybe Int16, b :: Maybe LocalTime } deriving GHC.Generic
777-- >>> instance Generic Row
768-- >>> instance Generic Row
778-- >>> instance HasDatatypeInfo Row
769-- >>> instance HasDatatypeInfo Row
779−-- >>> :kind! FieldTypesWith Row
770+-- >>> :kind! FieldTypesFrom Row
780−-- FieldTypesWith Row :: [PGType]
771+-- FieldTypesFrom Row :: [PGType]
781-- = '['PGint2, 'PGtimestamp]
772-- = '['PGint2, 'PGtimestamp]
782−type family FieldTypesWith (hask :: Type) :: [PGType] where
773+type family FieldTypesFrom (hask :: Type) :: [PGType] where
783− FieldTypesWith hask = FieldTypesOf (RecordCodeOf hask (Code hask))
774+ FieldTypesFrom hask = FieldTypesOf (RecordCodeOf hask (Code hask))
785-- | Calculates constructors of a datatype.
776-- | Calculates constructors of a datatype.
786type family ConstructorsOf (datatype :: Type.DatatypeInfo)
777type family ConstructorsOf (datatype :: Type.DatatypeInfo)