@@ -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
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
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)
267+ (TableConstraintExpression sch tab schemas constraint) where
268+ renderSQL = renderTableConstraintExpression
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)
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 <> ";"
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
@@ -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
610-- | A `dropConstraint` drops a table constraint.
613-- | A `dropConstraint` drops a table constraint.
@@ -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 <> ";"
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 <> ";"
867-- | Enumerated types are created using the `createTypeEnum` command, for example
870-- | Enumerated types are created using the `createTypeEnum` command, for example
@@ -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) <> ";"
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
@@ -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) <> ";"
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 <> ";"
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)