@@ -123,23 +123,7 @@ createTable
123 -- ^ constraints that must hold for the table
123 -- ^ constraints that must hold for the table
124 -> Definition schema (Create table (constraints :=> columns) schema)
124 -> Definition schema (Create table (constraints :=> columns) schema)
125createTable table columns constraints = UnsafeDefinition $
125createTable table columns constraints = UnsafeDefinition $
126− "CREATE TABLE" <+> renderAlias table
126+ "CREATE TABLE" <+> renderCreation table columns constraints
128− ( renderCommaSeparated renderColumnDef columns
129− <> ( case constraints of
132− renderCommaSeparated renderConstraint constraints ) )
135− renderColumnDef :: Aliased TypeExpression x -> ByteString
136− renderColumnDef (ty `As` column) =
137− renderAlias column <+> renderTypeExpression ty
139− :: Aliased (TableConstraintExpression schema columns) constraint
141− renderConstraint (constraint `As` alias) =
142− "CONSTRAINT" <+> renderAlias alias <+> renderTableConstraintExpression constraint
144-- | `createTable` adds a table to the schema.
128-- | `createTable` adds a table to the schema.
@@ -150,8 +134,7 @@ createTable table columns constraints = UnsafeDefinition $
151-- "CREATE TABLE tab (a int, b real);"
135-- "CREATE TABLE tab (a int, b real);"
152createTableIfNotExists
136createTableIfNotExists
153− :: ( KnownSymbol table
137+ :: ( Has table schema (constraints :=> columns)
154− , columns ~ (col ': cols)
155 , SOP.SListI columns
138 , SOP.SListI columns
156 , SOP.SListI constraints )
139 , SOP.SListI constraints )
157 => Alias table -- ^ the name of the table to add
140 => Alias table -- ^ the name of the table to add
@@ -159,9 +142,23 @@ createTableIfNotExists
159 -- ^ the names and datatype of each column
142 -- ^ the names and datatype of each column
160 -> NP (Aliased (TableConstraintExpression schema columns)) constraints
143 -> NP (Aliased (TableConstraintExpression schema columns)) constraints
161 -- ^ constraints that must hold for the table
144 -- ^ constraints that must hold for the table
162− -> Definition schema (Create table (constraints :=> columns) schema)
145+ -> Definition schema schema
163createTableIfNotExists table columns constraints = UnsafeDefinition $
146createTableIfNotExists table columns constraints = UnsafeDefinition $
164− "CREATE TABLE IF NOT EXISTS" <+> renderAlias table
147+ "CREATE TABLE IF NOT EXISTS"
148+ <+> renderCreation table columns constraints
150+-- helper function for `createTable` and `createTableIfNotExists`
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
161+renderCreation table columns constraints = renderAlias table
165 <+> parenthesized
162 <+> parenthesized
166 ( renderCommaSeparated renderColumnDef columns
163 ( renderCommaSeparated renderColumnDef columns
167 <> ( case constraints of
164 <> ( case constraints of