@@ -629,13 +629,18 @@ type family DropIfConstraintsInvolve column constraints where
629 (DropIfConstraintsInvolve column constraints)
629 (DropIfConstraintsInvolve column constraints)
630 (alias ::: constraint ': DropIfConstraintsInvolve column constraints)
630 (alias ::: constraint ': DropIfConstraintsInvolve column constraints)
632+-- | A `SchemumType` is a user-defined type, either a `Table`,
633+-- `View` or `Typedef`.
632data SchemumType
634data SchemumType
633 = Table TableType
635 = Table TableType
634 | View RelationType
636 | View RelationType
635 | Typedef PGType
637 | Typedef PGType
639+-- | The schema of a database consists of a list of aliased,
640+-- user-defined `SchemumType`s.
637type SchemaType = [(Symbol,SchemumType)]
641type SchemaType = [(Symbol,SchemumType)]
643+-- | Used in `Squeal.Postgresql.Manipulation.with`.
639type family With
644type family With
640 (relations :: RelationsType)
645 (relations :: RelationsType)
641 (schema :: SchemaType)
646 (schema :: SchemaType)
@@ -644,27 +649,38 @@ type family With
644 With (alias ::: rel ': rels) schema =
649 With (alias ::: rel ': rels) schema =
645 alias ::: 'View rel ': With rels schema
650 alias ::: 'View rel ': With rels schema
652+-- | `IsPGlabel` looks very much like the `IsLabel` class. Whereas
653+-- the overloaded label, `fromLabel` is used for column references,
654+-- `label`s are used for enum terms. A `label` is called with
655+-- type application like `label @"beef"`.
647class IsPGlabel (label :: Symbol) expr where label :: expr
656class IsPGlabel (label :: Symbol) expr where label :: expr
648instance label ~ label'
657instance label ~ label'
649 => IsPGlabel label (PGlabel label') where label = PGlabel
658 => IsPGlabel label (PGlabel label') where label = PGlabel
659+-- | A `PGlabel` unit type with an `IsPGlabel` instance
650data PGlabel (label :: Symbol) = PGlabel
660data PGlabel (label :: Symbol) = PGlabel
651−
661+-- | Renders a label
652renderLabel :: KnownSymbol label => proxy label -> ByteString
662renderLabel :: KnownSymbol label => proxy label -> ByteString
653renderLabel (_ :: proxy label) =
663renderLabel (_ :: proxy label) =
654 "\'" <> fromString (symbolVal (Proxy @label)) <> "\'"
664 "\'" <> fromString (symbolVal (Proxy @label)) <> "\'"
655−
665+-- | Renders a list of labels
656renderLabels
666renderLabels
657 :: All KnownSymbol labels => NP PGlabel labels -> [ByteString]
667 :: All KnownSymbol labels => NP PGlabel labels -> [ByteString]
658renderLabels = hcollapse
668renderLabels = hcollapse
659 . hcmap (Proxy @KnownSymbol) (K . renderLabel)
669 . hcmap (Proxy @KnownSymbol) (K . renderLabel)
660−
670+-- | Gets the name of a type constructor
661type family LabelOf (cons :: Type.ConstructorInfo) :: Symbol where
671type family LabelOf (cons :: Type.ConstructorInfo) :: Symbol where
662 LabelOf ('Type.Constructor name) = name
672 LabelOf ('Type.Constructor name) = name
663−
673+-- | Gets the names of a list of type constructors
664type family LabelsOf (conss :: [Type.ConstructorInfo]) :: [Symbol] where
674type family LabelsOf (conss :: [Type.ConstructorInfo]) :: [Symbol] where
665 LabelsOf '[] = '[]
675 LabelsOf '[] = '[]
666 LabelsOf (cons ': conss) = LabelOf cons ': LabelsOf conss
676 LabelsOf (cons ': conss) = LabelOf cons ': LabelsOf conss
678+-- | The `PG` type family embeds a subset of Haskell types
679+-- as basic Postgres types.
681+-- >>> :kind! PG LocalTime
682+-- PG LocalTime :: PGType
668type family PG (hask :: Type) :: PGType where
684type family PG (hask :: Type) :: PGType where
669 PG Bool = 'PGbool
685 PG Bool = 'PGbool
670 PG Int16 = 'PGint2
686 PG Int16 = 'PGint2