@@ -123,23 +123,7 @@ createTable
123123 -- ^ constraints that must hold for the table
124124 -> Definition schema (Create table (constraints :=> columns) schema)
125125createTable table columns constraints = UnsafeDefinition $
126− "CREATE TABLE" <+> renderAlias table
127− <+> parenthesized
128− ( renderCommaSeparated renderColumnDef columns
129− <> ( case constraints of
130− Nil -> ""
131− _ -> ", " <>
132− renderCommaSeparated renderConstraint constraints ) )
133− <> ";"
134− where
135− renderColumnDef :: Aliased TypeExpression x -> ByteString
136− renderColumnDef (ty `As` column) =
137− renderAlias column <+> renderTypeExpression ty
138− renderConstraint
139− :: Aliased (TableConstraintExpression schema columns) constraint
140− -> ByteString
141− renderConstraint (constraint `As` alias) =
142− "CONSTRAINT" <+> renderAlias alias <+> renderTableConstraintExpression constraint
126+ "CREATE TABLE" <+> renderCreation table columns constraints
143127
144128-- | `createTable` adds a table to the schema.
145129--
@@ -150,8 +134,7 @@ createTable table columns constraints = UnsafeDefinition $
150134-- :}
151135-- "CREATE TABLE tab (a int, b real);"
152136createTableIfNotExists
153− :: ( KnownSymbol table
154− , columns ~ (col ': cols)
137+ :: ( Has table schema (constraints :=> columns)
155138 , SOP.SListI columns
156139 , SOP.SListI constraints )
157140 => Alias table -- ^ the name of the table to add
@@ -159,9 +142,23 @@ createTableIfNotExists
159142 -- ^ the names and datatype of each column
160143 -> NP (Aliased (TableConstraintExpression schema columns)) constraints
161144 -- ^ constraints that must hold for the table
162− -> Definition schema (Create table (constraints :=> columns) schema)
145+ -> Definition schema schema
163146createTableIfNotExists table columns constraints = UnsafeDefinition $
164− "CREATE TABLE IF NOT EXISTS" <+> renderAlias table
147+ "CREATE TABLE IF NOT EXISTS"
148+ <+> renderCreation table columns constraints
149+
150+-- helper function for `createTable` and `createTableIfNotExists`
151+renderCreation
152+ :: ( KnownSymbol table
153+ , SOP.SListI columns
154+ , SOP.SListI constraints )
155+ => Alias table -- ^ the name of the table to add
156+ -> NP (Aliased TypeExpression) columns
157+ -- ^ the names and datatype of each column
158+ -> NP (Aliased (TableConstraintExpression schema columns)) constraints
159+ -- ^ constraints that must hold for the table
160+ -> ByteString
161+renderCreation table columns constraints = renderAlias table
165162 <+> parenthesized
166163 ( renderCommaSeparated renderColumnDef columns
167164 <> ( case constraints of