@@ -19,6 +19,7 @@ A type-level DSL for kinds of PostgreSQL types, constraints, and aliases.
1919 , GADTs
2020 , OverloadedStrings
2121 , RankNTypes
22+ , ScopedTypeVariables
2223 , StandaloneDeriving
2324 , TypeApplications
2425 , TypeFamilyDependencies
@@ -93,6 +94,10 @@ module Squeal.PostgreSQL.Schema
9394 , SameLabels
9495 , MapMaybes (..)
9596 , Nulls
97+ , IsPGlabel (..)
98+ , PGlabel (..)
99+ , renderLabel
100+ , renderLabels
96101 -- * Schema
97102 , SchemumType (..)
98103 , SchemaType
@@ -618,3 +623,17 @@ type family With
618623 With '[] schema = schema
619624 With (alias ::: rel ': rels) schema =
620625 alias ::: 'View rel ': With rels schema
626+
627+class IsPGlabel (label :: Symbol) expr where label :: expr
628+instance label ~ label'
629+ => IsPGlabel label (PGlabel label') where label = PGlabel
630+data PGlabel (label :: Symbol) = PGlabel
631+
632+renderLabel :: KnownSymbol label => proxy label -> ByteString
633+renderLabel (_ :: proxy label) =
634+ "\'" <> fromString (symbolVal (SOP.Proxy @label)) <> "\'"
635+
636+renderLabels
637+ :: SOP.All KnownSymbol labels => SOP.NP PGlabel labels -> [ByteString]
638+renderLabels = SOP.hcollapse
639+ . SOP.hcmap (SOP.Proxy @KnownSymbol) (SOP.K . renderLabel)