on dev help sign in
more renderSQL
c571baeEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+16−13
@@ -119,7 +119,7 @@ instance RenderSQL (Definition schemas0 schemas1) where
119instance Category Definition where
119instance Category Definition where
120 id = UnsafeDefinition ";"
120 id = UnsafeDefinition ";"
121 ddl1 . ddl0 = UnsafeDefinition $
121 ddl1 . ddl0 = UnsafeDefinition $
122− renderDefinition ddl0 <> "\n" <> renderDefinition ddl1
122+ renderSQL ddl0 <> "\n" <> renderSQL ddl1
123
123
124{-----------------------------------------
124{-----------------------------------------
125CREATE statements
125CREATE statements
@@ -225,7 +225,7 @@ renderCreation
225 -> NP (Aliased (TableConstraintExpression sch tab schemas1)) constraints
225 -> NP (Aliased (TableConstraintExpression sch tab schemas1)) constraints
226 -- ^ constraints that must hold for the table
226 -- ^ constraints that must hold for the table
227 -> ByteString
227 -> ByteString
228−renderCreation tab columns constraints = renderQualifiedAlias tab
228+renderCreation tab columns constraints = renderSQL tab
229 <+> parenthesized
229 <+> parenthesized
230 ( renderCommaSeparated renderColumnDef columns
230 ( renderCommaSeparated renderColumnDef columns
231 <> ( case constraints of
231 <> ( case constraints of
@@ -241,7 +241,7 @@ renderCreation tab columns constraints = renderQualifiedAlias tab
241 :: Aliased (TableConstraintExpression sch tab schemas) constraint
241 :: Aliased (TableConstraintExpression sch tab schemas) constraint
242 -> ByteString
242 -> ByteString
243 renderConstraint (constraint `As` alias) =
243 renderConstraint (constraint `As` alias) =
244− "CONSTRAINT" <+> renderSQL alias <+> renderTableConstraintExpression constraint
244+ "CONSTRAINT" <+> renderSQL alias <+> renderSQL constraint
245
245
246-- | Data types are a way to limit the kind of data that can be stored in a
246-- | Data types are a way to limit the kind of data that can be stored in a
247-- table. For many applications, however, the constraint they provide is
247-- table. For many applications, however, the constraint they provide is
@@ -263,6 +263,9 @@ newtype TableConstraintExpression
263 = UnsafeTableConstraintExpression
263 = UnsafeTableConstraintExpression
264 { renderTableConstraintExpression :: ByteString }
264 { renderTableConstraintExpression :: ByteString }
265 deriving (GHC.Generic,Show,Eq,Ord,NFData)
265 deriving (GHC.Generic,Show,Eq,Ord,NFData)
266+instance RenderSQL
267+ (TableConstraintExpression sch tab schemas constraint) where
268+ renderSQL = renderTableConstraintExpression
266
269
267{-| A `check` constraint is the most generic `TableConstraint` type.
270{-| A `check` constraint is the most generic `TableConstraint` type.
268It allows you to specify that the value in a certain column must satisfy
271It allows you to specify that the value in a certain column must satisfy
@@ -298,7 +301,7 @@ check
298 -- ^ a closed `Condition` on those subcolumns
301 -- ^ a closed `Condition` on those subcolumns
299 -> TableConstraintExpression sch tab schemas ('Check aliases)
302 -> TableConstraintExpression sch tab schemas ('Check aliases)
300check _cols condition = UnsafeTableConstraintExpression $
303check _cols condition = UnsafeTableConstraintExpression $
301− "CHECK" <+> parenthesized (renderExpression condition)
304+ "CHECK" <+> parenthesized (renderSQL condition)
302
305
303{-| A `unique` constraint ensure that the data contained in a column,
306{-| A `unique` constraint ensure that the data contained in a column,
304or a group of columns, is unique among all the rows in the table.
307or a group of columns, is unique among all the rows in the table.
@@ -541,7 +544,7 @@ dropTable
541 , Has tab schema ('Table table))
544 , Has tab schema ('Table table))
542 => QualifiedAlias sch tab -- ^ table to remove
545 => QualifiedAlias sch tab -- ^ table to remove
543 -> Definition schemas (Alter sch (Drop tab schema) schemas)
546 -> Definition schemas (Alter sch (Drop tab schema) schemas)
544−dropTable tab = UnsafeDefinition $ "DROP TABLE" <+> renderQualifiedAlias tab <> ";"
547+dropTable tab = UnsafeDefinition $ "DROP TABLE" <+> renderSQL tab <> ";"
545
548
546{-----------------------------------------
549{-----------------------------------------
547ALTER statements
550ALTER statements
@@ -555,7 +558,7 @@ alterTable
555 -> Definition schemas (Alter sch (Alter tab ('Table table1) schema) schemas)
558 -> Definition schemas (Alter sch (Alter tab ('Table table1) schema) schemas)
556alterTable tab alteration = UnsafeDefinition $
559alterTable tab alteration = UnsafeDefinition $
557 "ALTER TABLE"
560 "ALTER TABLE"
558− <+> renderQualifiedAlias tab
561+ <+> renderSQL tab
559 <+> renderAlterTable alteration
562 <+> renderAlterTable alteration
560 <> ";"
563 <> ";"
561
564
@@ -605,7 +608,7 @@ addConstraint
605 -> AlterTable sch tab schemas table1
608 -> AlterTable sch tab schemas table1
606addConstraint alias constraint = UnsafeAlterTable $
609addConstraint alias constraint = UnsafeAlterTable $
607 "ADD" <+> "CONSTRAINT" <+> renderSQL alias
610 "ADD" <+> "CONSTRAINT" <+> renderSQL alias
608− <+> renderTableConstraintExpression constraint
611+ <+> renderSQL constraint
609
612
610-- | A `dropConstraint` drops a table constraint.
613-- | A `dropConstraint` drops a table constraint.
611--
614--
@@ -843,7 +846,7 @@ createView
843 -> Query ('[] :=> schemas) '[] view -- ^ query
846 -> Query ('[] :=> schemas) '[] view -- ^ query
844 -> Definition schemas (Alter sch (Create vw ('View view) schema) schemas)
847 -> Definition schemas (Alter sch (Create vw ('View view) schema) schemas)
845createView alias query = UnsafeDefinition $
848createView alias query = UnsafeDefinition $
846− "CREATE" <+> "VIEW" <+> renderQualifiedAlias alias <+> "AS"
849+ "CREATE" <+> "VIEW" <+> renderSQL alias <+> "AS"
847 <+> renderQuery query <> ";"
850 <+> renderQuery query <> ";"
848
851
849-- | Drop a view.
852-- | Drop a view.
@@ -862,7 +865,7 @@ dropView
862 :: (Has sch schemas schema, Has vw schema ('View view))
865 :: (Has sch schemas schema, Has vw schema ('View view))
863 => QualifiedAlias sch vw -- ^ view to remove
866 => QualifiedAlias sch vw -- ^ view to remove
864 -> Definition schemas (Alter sch (Drop vw schema) schemas)
867 -> Definition schemas (Alter sch (Drop vw schema) schemas)
865−dropView vw = UnsafeDefinition $ "DROP VIEW" <+> renderQualifiedAlias vw <> ";"
868+dropView vw = UnsafeDefinition $ "DROP VIEW" <+> renderSQL vw <> ";"
866
869
867-- | Enumerated types are created using the `createTypeEnum` command, for example
870-- | Enumerated types are created using the `createTypeEnum` command, for example
868--
871--
@@ -876,8 +879,8 @@ createTypeEnum
876 -- ^ labels of the enumerated type
879 -- ^ labels of the enumerated type
877 -> Definition schemas (Alter sch (Create enum ('Typedef ('PGenum labels)) schema) schemas)
880 -> Definition schemas (Alter sch (Create enum ('Typedef ('PGenum labels)) schema) schemas)
878createTypeEnum enum labels = UnsafeDefinition $
881createTypeEnum enum labels = UnsafeDefinition $
879− "CREATE" <+> "TYPE" <+> renderQualifiedAlias enum <+> "AS" <+> "ENUM" <+>
882+ "CREATE" <+> "TYPE" <+> renderSQL enum <+> "AS" <+> "ENUM" <+>
880− parenthesized (commaSeparated (renderLabels labels)) <> ";"
883+ parenthesized (renderSQL labels) <> ";"
881
884
882-- | Enumerated types can also be generated from a Haskell type, for example
885-- | Enumerated types can also be generated from a Haskell type, for example
883--
886--
@@ -930,7 +933,7 @@ createTypeComposite
930 -- ^ list of attribute names and data types
933 -- ^ list of attribute names and data types
931 -> Definition schemas (Alter sch (Create ty ('Typedef ('PGcomposite fields)) schema) schemas)
934 -> Definition schemas (Alter sch (Create ty ('Typedef ('PGcomposite fields)) schema) schemas)
932createTypeComposite ty fields = UnsafeDefinition $
935createTypeComposite ty fields = UnsafeDefinition $
933− "CREATE" <+> "TYPE" <+> renderQualifiedAlias ty <+> "AS" <+> parenthesized
936+ "CREATE" <+> "TYPE" <+> renderSQL ty <+> "AS" <+> parenthesized
934 (renderCommaSeparated renderField fields) <> ";"
937 (renderCommaSeparated renderField fields) <> ";"
935 where
938 where
936 renderField :: Aliased (TypeExpression schemas) x -> ByteString
939 renderField :: Aliased (TypeExpression schemas) x -> ByteString
@@ -981,7 +984,7 @@ dropType
981 => QualifiedAlias sch td
984 => QualifiedAlias sch td
982 -- ^ name of the user defined type
985 -- ^ name of the user defined type
983 -> Definition schemas (Alter sch (Drop td schema) schemas)
986 -> Definition schemas (Alter sch (Drop td schema) schemas)
984−dropType tydef = UnsafeDefinition $ "DROP" <+> "TYPE" <+> renderQualifiedAlias tydef <> ";"
987+dropType tydef = UnsafeDefinition $ "DROP" <+> "TYPE" <+> renderSQL tydef <> ";"
985
988
986-- | `ColumnTypeExpression`s are used in `createTable` commands.
989-- | `ColumnTypeExpression`s are used in `createTable` commands.
987newtype ColumnTypeExpression (schemas :: SchemasType) (ty :: ColumnType)
990newtype ColumnTypeExpression (schemas :: SchemasType) (ty :: ColumnType)
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+5−5
@@ -452,7 +452,7 @@ index n expr = UnsafeExpression $
452
452
453instance (KnownSymbol label, label `In` labels) => IsPGlabel label
453instance (KnownSymbol label, label `In` labels) => IsPGlabel label
454 (Expression db params grp from (nullity ('PGenum labels))) where
454 (Expression db params grp from (nullity ('PGenum labels))) where
455− label = UnsafeExpression $ renderLabel (PGlabel @label)
455+ label = UnsafeExpression $ renderSQL (PGlabel @label)
456
456
457-- | A row constructor is an expression that builds a row value
457-- | A row constructor is an expression that builds a row value
458-- (also called a composite value) using values for its member fields.
458-- (also called a composite value) using values for its member fields.
@@ -494,7 +494,7 @@ field
494 -> Expression (commons :=> schemas) params grp from ('NotNull ('PGcomposite row))
494 -> Expression (commons :=> schemas) params grp from ('NotNull ('PGcomposite row))
495 -> Expression (commons :=> schemas) params grp from ty
495 -> Expression (commons :=> schemas) params grp from ty
496field td fld expr = UnsafeExpression $
496field td fld expr = UnsafeExpression $
497− parenthesized (renderSQL expr <> "::" <> renderQualifiedAlias td)
497+ parenthesized (renderSQL expr <> "::" <> renderSQL td)
498 <> "." <> renderSQL fld
498 <> "." <> renderSQL fld
499
499
500instance Semigroup
500instance Semigroup
@@ -1637,7 +1637,7 @@ typedef
1637 :: (Has sch schemas schema, Has td schema ('Typedef ty))
1637 :: (Has sch schemas schema, Has td schema ('Typedef ty))
1638 => QualifiedAlias sch td
1638 => QualifiedAlias sch td
1639 -> TypeExpression schemas (nullity ty)
1639 -> TypeExpression schemas (nullity ty)
1640−typedef = UnsafeTypeExpression . renderQualifiedAlias
1640+typedef = UnsafeTypeExpression . renderSQL
1641
1641
1642-- | The composite type corresponding to a `Table` definition can be expressed
1642-- | The composite type corresponding to a `Table` definition can be expressed
1643-- by its alias.
1643-- by its alias.
@@ -1645,7 +1645,7 @@ typetable
1645 :: (Has sch schemas schema, Has tab schema ('Table table))
1645 :: (Has sch schemas schema, Has tab schema ('Table table))
1646 => QualifiedAlias sch tab
1646 => QualifiedAlias sch tab
1647 -> TypeExpression schemas (nullity ('PGcomposite (TableToRow table)))
1647 -> TypeExpression schemas (nullity ('PGcomposite (TableToRow table)))
1648−typetable = UnsafeTypeExpression . renderQualifiedAlias
1648+typetable = UnsafeTypeExpression . renderSQL
1649
1649
1650-- | The composite type corresponding to a `View` definition can be expressed
1650-- | The composite type corresponding to a `View` definition can be expressed
1651-- by its alias.
1651-- by its alias.
@@ -1653,7 +1653,7 @@ typeview
1653 :: (Has sch schemas schema, Has vw schema ('View view))
1653 :: (Has sch schemas schema, Has vw schema ('View view))
1654 => QualifiedAlias sch vw
1654 => QualifiedAlias sch vw
1655 -> TypeExpression schemas (nullity ('PGcomposite view))
1655 -> TypeExpression schemas (nullity ('PGcomposite view))
1656−typeview = UnsafeTypeExpression . renderQualifiedAlias
1656+typeview = UnsafeTypeExpression . renderSQL
1657
1657
1658-- | logical Boolean (true/false)
1658-- | logical Boolean (true/false)
1659bool :: TypeExpression schemas (nullity 'PGbool)
1659bool :: TypeExpression schemas (nullity 'PGbool)
squeal-postgresql/src/Squeal/PostgreSQL/Manipulation.hs+3−3
@@ -240,7 +240,7 @@ insertInto
240 -> ReturningClause db params '[tab ::: row0] row1
240 -> ReturningClause db params '[tab ::: row0] row1
241 -> Manipulation db params row1
241 -> Manipulation db params row1
242insertInto tab qry conflict ret = UnsafeManipulation $
242insertInto tab qry conflict ret = UnsafeManipulation $
243− "INSERT" <+> "INTO" <+> renderQualifiedAlias tab
243+ "INSERT" <+> "INTO" <+> renderSQL tab
244 <+> renderQueryClause qry
244 <+> renderQueryClause qry
245 <> renderConflictClause conflict
245 <> renderConflictClause conflict
246 <> renderSQL ret
246 <> renderSQL ret
@@ -508,7 +508,7 @@ update
508 -> Manipulation db params row1
508 -> Manipulation db params row1
509update tab columns wh returning = UnsafeManipulation $
509update tab columns wh returning = UnsafeManipulation $
510 "UPDATE"
510 "UPDATE"
511− <+> renderQualifiedAlias tab
511+ <+> renderSQL tab
512 <+> "SET"
512 <+> "SET"
513 <+> renderCommaSeparated renderColumnExpression columns
513 <+> renderCommaSeparated renderColumnExpression columns
514 <+> "WHERE" <+> renderExpression wh
514 <+> "WHERE" <+> renderExpression wh
@@ -558,7 +558,7 @@ deleteFrom
558 -> Manipulation db params row1
558 -> Manipulation db params row1
559deleteFrom tab using wh returning = UnsafeManipulation $
559deleteFrom tab using wh returning = UnsafeManipulation $
560 "DELETE FROM"
560 "DELETE FROM"
561− <+> renderQualifiedAlias tab
561+ <+> renderSQL tab
562 <> case using of
562 <> case using of
563 NoUsing -> ""
563 NoUsing -> ""
564 Using tables -> " USING" <+> renderFromClause tables
564 Using tables -> " USING" <+> renderFromClause tables
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+15−16
@@ -97,7 +97,6 @@ module Squeal.PostgreSQL.Query
97 , renderHavingClause
97 , renderHavingClause
98 -- * Sorting
98 -- * Sorting
99 , SortExpression (..)
99 , SortExpression (..)
100− , renderSortExpression
101 -- * Subquery Expressions
100 -- * Subquery Expressions
102 , in_
101 , in_
103 , rowIn
102 , rowIn
@@ -439,7 +438,7 @@ instance
439
438
440instance RenderSQL (Selection db params grp from row) where
439instance RenderSQL (Selection db params grp from row) where
441 renderSQL = \case
440 renderSQL = \case
442− List list -> renderCommaSeparated (renderAliasedAs renderSQL) list
441+ List list -> renderCommaSeparated (renderAliased renderSQL) list
443 Star -> "*"
442 Star -> "*"
444 DotStar tab -> renderSQL tab <> ".*"
443 DotStar tab -> renderSQL tab <> ".*"
445 Also right left -> renderSQL left <> ", " <> renderSQL right
444 Also right left -> renderSQL left <> ", " <> renderSQL right
@@ -609,7 +608,7 @@ renderTableExpression
609 renderOrderByClause = \case
608 renderOrderByClause = \case
610 [] -> ""
609 [] -> ""
611 srts -> " ORDER BY"
610 srts -> " ORDER BY"
612− <+> commaSeparated (renderSortExpression <$> srts)
611+ <+> commaSeparated (renderSQL <$> srts)
613 renderLimits = \case
612 renderLimits = \case
614 [] -> ""
613 [] -> ""
615 lims -> " LIMIT" <+> fromString (show (minimum lims))
614 lims -> " LIMIT" <+> fromString (show (minimum lims))
@@ -845,13 +844,13 @@ table
845 => Aliased (QualifiedAlias sch) (alias ::: tab)
844 => Aliased (QualifiedAlias sch) (alias ::: tab)
846 -> FromClause (commons :=> schemas) params '[alias ::: TableToRow table]
845 -> FromClause (commons :=> schemas) params '[alias ::: TableToRow table]
847table (tab `As` alias) = UnsafeFromClause $
846table (tab `As` alias) = UnsafeFromClause $
848− renderQualifiedAlias tab <+> "AS" <+> renderSQL alias
847+ renderSQL tab <+> "AS" <+> renderSQL alias
849
848
850-- | `subquery` derives a table from a `Query`.
849-- | `subquery` derives a table from a `Query`.
851subquery
850subquery
852 :: Aliased (Query db params) query
851 :: Aliased (Query db params) query
853 -> FromClause db params '[query]
852 -> FromClause db params '[query]
854−subquery = UnsafeFromClause . renderAliasedAs (parenthesized . renderQuery)
853+subquery = UnsafeFromClause . renderAliased (parenthesized . renderQuery)
855
854
856-- | `view` derives a table from a `View`.
855-- | `view` derives a table from a `View`.
857view
856view
@@ -859,7 +858,7 @@ view
859 => Aliased (QualifiedAlias sch) (alias ::: vw)
858 => Aliased (QualifiedAlias sch) (alias ::: vw)
860 -> FromClause (commons :=> schemas) params '[alias ::: view]
859 -> FromClause (commons :=> schemas) params '[alias ::: view]
861view (vw `As` alias) = UnsafeFromClause $
860view (vw `As` alias) = UnsafeFromClause $
862− renderQualifiedAlias vw <+> "AS" <+> renderSQL alias
861+ renderSQL vw <+> "AS" <+> renderSQL alias
863
862
864common
863common
865 :: Has cte commons common
864 :: Has cte commons common
@@ -1069,16 +1068,16 @@ data SortExpression db params grp from where
1069deriving instance Show (SortExpression db params grp from)
1068deriving instance Show (SortExpression db params grp from)
1070
1069
1071-- | Render a `SortExpression`.
1070-- | Render a `SortExpression`.
1072−renderSortExpression :: SortExpression db params grp from -> ByteString
1071+instance RenderSQL (SortExpression db params grp from) where
1073−renderSortExpression = \case
1072+ renderSQL = \case
1074− Asc expression -> renderSQL expression <+> "ASC"
1073+ Asc expression -> renderSQL expression <+> "ASC"
1075− Desc expression -> renderSQL expression <+> "DESC"
1074+ Desc expression -> renderSQL expression <+> "DESC"
1076− AscNullsFirst expression -> renderSQL expression
1075+ AscNullsFirst expression -> renderSQL expression
1077− <+> "ASC NULLS FIRST"
1076+ <+> "ASC NULLS FIRST"
1078− DescNullsFirst expression -> renderSQL expression
1077+ DescNullsFirst expression -> renderSQL expression
1079− <+> "DESC NULLS FIRST"
1078+ <+> "DESC NULLS FIRST"
1080− AscNullsLast expression -> renderSQL expression <+> "ASC NULLS LAST"
1079+ AscNullsLast expression -> renderSQL expression <+> "ASC NULLS LAST"
1081− DescNullsLast expression -> renderSQL expression <+> "DESC NULLS LAST"
1080+ DescNullsLast expression -> renderSQL expression <+> "DESC NULLS LAST"
1082
1081
1083unsafeSubqueryExpression
1082unsafeSubqueryExpression
1084 :: ByteString
1083 :: ByteString
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+23−29
@@ -70,7 +70,7 @@ module Squeal.PostgreSQL.Schema
70 , IsLabel (..)
70 , IsLabel (..)
71 , Aliased (As)
71 , Aliased (As)
72 , Aliasable (as)
72 , Aliasable (as)
73− , renderAliasedAs
73+ , renderAliased
74 , Has
74 , Has
75 , HasUnique
75 , HasUnique
76 , HasAll
76 , HasAll
@@ -80,12 +80,9 @@ module Squeal.PostgreSQL.Schema
80 , IsNotElem
80 , IsNotElem
81 , AllUnique
81 , AllUnique
82 , DefaultAliasable (..)
82 , DefaultAliasable (..)
83− , renderQualifiedAlias
84 -- * Enumerated Labels
83 -- * Enumerated Labels
85 , IsPGlabel (..)
84 , IsPGlabel (..)
86 , PGlabel (..)
85 , PGlabel (..)
87− , renderLabel
88− , renderLabels
89 , LabelsPG
86 , LabelsPG
90 -- * Grouping
87 -- * Grouping
91 , Grouping (..)
88 , Grouping (..)
@@ -374,14 +371,14 @@ instance alias1 ~ alias2 => IsLabel alias1 (Alias alias2) where
374 fromLabel = Alias
371 fromLabel = Alias
375instance aliases ~ '[alias] => IsLabel alias (NP Alias aliases) where
372instance aliases ~ '[alias] => IsLabel alias (NP Alias aliases) where
376 fromLabel = fromLabel :* Nil
373 fromLabel = fromLabel :* Nil
377−-- | >>> renderSQL #jimbob
374+-- | >>> printSQL (#jimbob :: Alias "jimbob")
378−-- "\"jimbob\""
375+-- "jimbob"
379instance KnownSymbol alias => RenderSQL (Alias alias) where
376instance KnownSymbol alias => RenderSQL (Alias alias) where
380 renderSQL = doubleQuoted . fromString . symbolVal
377 renderSQL = doubleQuoted . fromString . symbolVal
381
378
382-- | >>> import Generics.SOP (NP(..))
379-- | >>> import Generics.SOP (NP(..))
383−-- >>> renderAliases (#jimbob :* #kandi)
384−-- ["\"jimbob\"","\"kandi\""]
380+-- >>> printSQL (#jimbob :* #kandi :: NP Alias '["jimbob", "kandi"])
381+-- "jimbob", "kandi"
385instance All KnownSymbol aliases => RenderSQL (NP Alias aliases) where
382instance All KnownSymbol aliases => RenderSQL (NP Alias aliases) where
386 renderSQL
383 renderSQL
387 = commaSeparated
384 = commaSeparated
@@ -427,13 +424,13 @@ instance (KnownSymbol alias, tys ~ '[alias ::: ty]) => Aliasable alias
427 expression `as` alias = expression `As` alias :* Nil
424 expression `as` alias = expression `As` alias :* Nil
428
425
429-- | >>> let renderMaybe = fromString . maybe "Nothing" (const "Just")
426-- | >>> let renderMaybe = fromString . maybe "Nothing" (const "Just")
430−-- >>> renderAliasedAs renderMaybe (Just (3::Int) `As` #an_int)
427+-- >>> renderAliased renderMaybe (Just (3::Int) `As` #an_int)
431-- "Just AS \"an_int\""
428-- "Just AS \"an_int\""
432−renderAliasedAs
429+renderAliased
433 :: (forall ty. expression ty -> ByteString)
430 :: (forall ty. expression ty -> ByteString)
434 -> Aliased expression aliased
431 -> Aliased expression aliased
435 -> ByteString
432 -> ByteString
436−renderAliasedAs render (expression `As` alias) =
433+renderAliased render (expression `As` alias) =
437 render expression <> " AS " <> renderSQL alias
434 render expression <> " AS " <> renderSQL alias
438
435
439-- | @HasUnique alias fields field@ is a constraint that proves that
436-- | @HasUnique alias fields field@ is a constraint that proves that
@@ -505,15 +502,14 @@ instance (q ~ "public", a0 ~ a1, a1 ~ a2, KnownSymbol a2) =>
505 IsLabel a0 (Aliased (QualifiedAlias q) (a1 ::: a2)) where
502 IsLabel a0 (Aliased (QualifiedAlias q) (a1 ::: a2)) where
506 fromLabel = QualifiedAlias `As` Alias
503 fromLabel = QualifiedAlias `As` Alias
507
504
508−renderQualifiedAlias
509− :: forall q a. (KnownSymbol q, KnownSymbol a)
505+instance (KnownSymbol q, KnownSymbol a)
510− => QualifiedAlias q a -> ByteString
506+ => RenderSQL (QualifiedAlias q a) where
511−renderQualifiedAlias _ =
507+ renderSQL _ =
512− let
508+ let
513− qualifier = renderSQL (Alias @q)
509+ qualifier = renderSQL (Alias @q)
514− alias = renderSQL (Alias @a)
510+ alias = renderSQL (Alias @a)
515− in
511+ in
516− if qualifier == "\"public\"" then alias else qualifier <> "." <> alias
512+ if qualifier == "\"public\"" then alias else qualifier <> "." <> alias
517
513
518-- | @Elem@ is a promoted `Data.List.elem`.
514-- | @Elem@ is a promoted `Data.List.elem`.
519type family Elem x xs where
515type family Elem x xs where
@@ -721,15 +717,13 @@ instance labels ~ '[label]
721 => IsPGlabel label (NP PGlabel labels) where label = PGlabel :* Nil
717 => IsPGlabel label (NP PGlabel labels) where label = PGlabel :* Nil
722-- | A `PGlabel` unit type with an `IsPGlabel` instance
718-- | A `PGlabel` unit type with an `IsPGlabel` instance
723data PGlabel (label :: Symbol) = PGlabel
719data PGlabel (label :: Symbol) = PGlabel
724−-- | Renders a label
725−renderLabel :: KnownSymbol label => proxy label -> ByteString
720+instance KnownSymbol label => RenderSQL (PGlabel label) where
726−renderLabel (_ :: proxy label) =
727− "\'" <> renderSymbol @label <> "\'"
721+ renderSQL _ = "\'" <> renderSymbol @label <> "\'"
728−-- | Renders a list of labels
729−renderLabels
730− :: All KnownSymbol labels => NP PGlabel labels -> [ByteString]
722+instance All KnownSymbol labels => RenderSQL (NP PGlabel labels) where
723+ renderSQL
724+ = commaSeparated
731−renderLabels = hcollapse
725+ . hcollapse
732− . hcmap (Proxy @KnownSymbol) (K . renderLabel)
726+ . hcmap (Proxy @KnownSymbol) (K . renderSQL)
733
727
734{- | The `PG` type family embeds a subset of Haskell types
728{- | The `PG` type family embeds a subset of Haskell types
735as Postgres types. As an open type family, `PG` is extensible.
729as Postgres types. As an open type family, `PG` is extensible.