@@ -88,8 +88,8 @@ statements
88-- database, like a `createTable`, `dropTable`, or `alterTable` command.
88-- database, like a `createTable`, `dropTable`, or `alterTable` command.
89-- `Definition`s may be composed using the `>>>` operator.
89-- `Definition`s may be composed using the `>>>` operator.
90newtype Definition
90newtype Definition
91− (schema0 :: TablesType)
91+ (schema0 :: SchemaType)
92− (schema1 :: TablesType)
92+ (schema1 :: SchemaType)
93 = UnsafeDefinition { renderDefinition :: ByteString }
93 = UnsafeDefinition { renderDefinition :: ByteString }
94 deriving (GHC.Generic,Show,Eq,Ord,NFData)
94 deriving (GHC.Generic,Show,Eq,Ord,NFData)
@@ -115,7 +115,7 @@ createTable
115 , columns ~ (col ': cols)
115 , columns ~ (col ': cols)
116 , SOP.SListI columns
116 , SOP.SListI columns
117 , SOP.SListI constraints
117 , SOP.SListI constraints
118− , schema1 ~ Create table (constraints :=> columns) schema0 )
118+ , schema1 ~ Create table ('Table (constraints :=> columns)) schema0 )
119 => Alias table -- ^ the name of the table to add
119 => Alias table -- ^ the name of the table to add
120 -> NP (Aliased TypeExpression) columns
120 -> NP (Aliased TypeExpression) columns
121 -- ^ the names and datatype of each column
121 -- ^ the names and datatype of each column
@@ -138,7 +138,7 @@ createTable table columns constraints = UnsafeDefinition $
139-- "CREATE TABLE IF NOT EXISTS \"tab\" (\"a\" int, \"b\" real);"
139-- "CREATE TABLE IF NOT EXISTS \"tab\" (\"a\" int, \"b\" real);"
140createTableIfNotExists
140createTableIfNotExists
141− :: ( Has table schema (constraints :=> columns)
141+ :: ( Has table (TablesOf schema) (constraints :=> columns)
142 , SOP.SListI columns
142 , SOP.SListI columns
143 , SOP.SListI constraints )
143 , SOP.SListI constraints )
144 => Alias table -- ^ the name of the table to add
144 => Alias table -- ^ the name of the table to add
@@ -193,7 +193,7 @@ renderCreation table columns constraints = renderAlias table
193-- violate a constraint, an error is raised. This applies
193-- violate a constraint, an error is raised. This applies
194-- even if the value came from the default value definition.
194-- even if the value came from the default value definition.
195newtype TableConstraintExpression
195newtype TableConstraintExpression
196− (schema :: TablesType)
196+ (schema :: SchemaType)
197 (table :: Symbol)
197 (table :: Symbol)
198 (tableConstraint :: TableConstraint)
198 (tableConstraint :: TableConstraint)
199 = UnsafeTableConstraintExpression
199 = UnsafeTableConstraintExpression
@@ -224,7 +224,7 @@ newtype TableConstraintExpression
224-- >>> renderDefinition definition
224-- >>> renderDefinition definition
225-- "CREATE TABLE \"tab\" (\"a\" int NOT NULL, \"b\" int NOT NULL, CONSTRAINT \"inequality\" CHECK ((\"a\" > \"b\")));"
225-- "CREATE TABLE \"tab\" (\"a\" int NOT NULL, \"b\" int NOT NULL, CONSTRAINT \"inequality\" CHECK ((\"a\" > \"b\")));"
227− :: ( Has alias schema table
227+ :: ( Has alias (TablesOf schema) table
228 , HasAll aliases (TableToColumns table) subcolumns )
228 , HasAll aliases (TableToColumns table) subcolumns )
229 => NP Alias aliases
229 => NP Alias aliases
230 -> (forall tab. Condition '[tab ::: ColumnsToRelation subcolumns] 'Ungrouped '[])
230 -> (forall tab. Condition '[tab ::: ColumnsToRelation subcolumns] 'Ungrouped '[])
@@ -255,7 +255,7 @@ check _cols condition = UnsafeTableConstraintExpression $
255-- >>> renderDefinition definition
255-- >>> renderDefinition definition
256-- "CREATE TABLE \"tab\" (\"a\" int, \"b\" int, CONSTRAINT \"uq_a_b\" UNIQUE (\"a\", \"b\"));"
256-- "CREATE TABLE \"tab\" (\"a\" int, \"b\" int, CONSTRAINT \"uq_a_b\" UNIQUE (\"a\", \"b\"));"
258− :: ( Has alias schema table
258+ :: ( Has alias (TablesOf schema) table
259 , HasAll aliases (TableToColumns table) subcolumns )
259 , HasAll aliases (TableToColumns table) subcolumns )
260 => NP Alias aliases
260 => NP Alias aliases
261 -> TableConstraintExpression schema alias ('Unique aliases)
261 -> TableConstraintExpression schema alias ('Unique aliases)
@@ -286,7 +286,7 @@ unique columns = UnsafeTableConstraintExpression $
286-- >>> renderDefinition definition
286-- >>> renderDefinition definition
287-- "CREATE TABLE \"tab\" (\"id\" serial, \"name\" text NOT NULL, CONSTRAINT \"pk_id\" PRIMARY KEY (\"id\"));"
287-- "CREATE TABLE \"tab\" (\"id\" serial, \"name\" text NOT NULL, CONSTRAINT \"pk_id\" PRIMARY KEY (\"id\"));"
288primaryKey
288primaryKey
289− :: ( Has alias schema table
289+ :: ( Has alias (TablesOf schema) table
290 , HasAll aliases (TableToColumns table) subcolumns
290 , HasAll aliases (TableToColumns table) subcolumns
291 , AllNotNull subcolumns )
291 , AllNotNull subcolumns )
292 => NP Alias aliases
292 => NP Alias aliases
@@ -397,8 +397,8 @@ type ForeignKeyed schema
397 columns refcolumns
397 columns refcolumns
398 constraints cols
398 constraints cols
399 reftys tys =
399 reftys tys =
400− ( Has child schema table
400+ ( Has child (TablesOf schema) table
401− , Has parent schema reftable
401+ , Has parent (TablesOf schema) reftable
402 , HasAll columns (TableToColumns table) tys
402 , HasAll columns (TableToColumns table) tys
403 , reftable ~ (constraints :=> cols)
403 , reftable ~ (constraints :=> cols)
404 , HasAll refcolumns cols reftys
404 , HasAll refcolumns cols reftys
@@ -467,7 +467,7 @@ alterTable
467 :: KnownSymbol alias
467 :: KnownSymbol alias
468 => Alias alias -- ^ table to alter
468 => Alias alias -- ^ table to alter
469 -> AlterTable alias table schema -- ^ alteration to perform
469 -> AlterTable alias table schema -- ^ alteration to perform
470− -> Definition schema (Alter alias table schema)
470+ -> Definition schema (Alter alias ('Table table) schema)
471alterTable table alteration = UnsafeDefinition $
471alterTable table alteration = UnsafeDefinition $
472 "ALTER TABLE"
472 "ALTER TABLE"
473 <+> renderAlias table
473 <+> renderAlias table
@@ -492,7 +492,7 @@ alterTableRename table0 table1 = UnsafeDefinition $
492newtype AlterTable
492newtype AlterTable
493 (alias :: Symbol)
493 (alias :: Symbol)
494 (table :: TableType)
494 (table :: TableType)
495− (schema :: TablesType) =
495+ (schema :: SchemaType) =
496 UnsafeAlterTable {renderAlterTable :: ByteString}
496 UnsafeAlterTable {renderAlterTable :: ByteString}
497 deriving (GHC.Generic,Show,Eq,Ord,NFData)
497 deriving (GHC.Generic,Show,Eq,Ord,NFData)
@@ -509,7 +509,7 @@ newtype AlterTable
509-- "ALTER TABLE \"tab\" ADD CONSTRAINT \"positive\" CHECK ((\"col\" > 0));"
509-- "ALTER TABLE \"tab\" ADD CONSTRAINT \"positive\" CHECK ((\"col\" > 0));"
510addConstraint
510addConstraint
511 :: ( KnownSymbol alias
511 :: ( KnownSymbol alias
512− , Has tab schema table0
512+ , Has tab (TablesOf schema) table0
513 , table0 ~ (constraints :=> columns)
513 , table0 ~ (constraints :=> columns)
514 , table1 ~ (Create alias constraint constraints :=> columns) )
514 , table1 ~ (Create alias constraint constraints :=> columns) )
515 => Alias alias
515 => Alias alias
@@ -533,7 +533,7 @@ addConstraint alias constraint = UnsafeAlterTable $
533-- "ALTER TABLE \"tab\" DROP CONSTRAINT \"positive\";"
533-- "ALTER TABLE \"tab\" DROP CONSTRAINT \"positive\";"
534dropConstraint
534dropConstraint
535 :: ( KnownSymbol constraint
535 :: ( KnownSymbol constraint
536− , Has tab schema table0
536+ , Has tab (TablesOf schema) table0
537 , table0 ~ (constraints :=> columns)
537 , table0 ~ (constraints :=> columns)
538 , table1 ~ (Drop constraint constraints :=> columns) )
538 , table1 ~ (Drop constraint constraints :=> columns) )
539 => Alias constraint
539 => Alias constraint
@@ -572,7 +572,7 @@ class AddColumn ty where
572 -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text;"
572 -- "ALTER TABLE \"tab\" ADD COLUMN \"col2\" text;"
573 addColumn
573 addColumn
574 :: ( KnownSymbol column
574 :: ( KnownSymbol column
575− , Has tab schema table0
575+ , Has tab (TablesOf schema) table0
576 , table0 ~ (constraints :=> columns)
576 , table0 ~ (constraints :=> columns)
577 , table1 ~ (constraints :=> Create column ty columns) )
577 , table1 ~ (constraints :=> Create column ty columns) )
578 => Alias column -- ^ column to add
578 => Alias column -- ^ column to add
@@ -601,7 +601,7 @@ instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
601-- "ALTER TABLE \"tab\" DROP COLUMN \"col2\";"
601-- "ALTER TABLE \"tab\" DROP COLUMN \"col2\";"
602dropColumn
602dropColumn
603 :: ( KnownSymbol column
603 :: ( KnownSymbol column
604− , Has tab schema table0
604+ , Has tab (TablesOf schema) table0
605 , table0 ~ (constraints :=> columns)
605 , table0 ~ (constraints :=> columns)
606 , table1 ~ (constraints :=> Drop column columns) )
606 , table1 ~ (constraints :=> Drop column columns) )
607 => Alias column -- ^ column to remove
607 => Alias column -- ^ column to remove
@@ -623,7 +623,7 @@ dropColumn column = UnsafeAlterTable $
623renameColumn
623renameColumn
624 :: ( KnownSymbol column0
624 :: ( KnownSymbol column0
625 , KnownSymbol column1
625 , KnownSymbol column1
626− , Has tab schema table0
626+ , Has tab (TablesOf schema) table0
627 , table0 ~ (constraints :=> columns)
627 , table0 ~ (constraints :=> columns)
628 , table1 ~ (constraints :=> Rename column0 column1 columns) )
628 , table1 ~ (constraints :=> Rename column0 column1 columns) )
629 => Alias column0 -- ^ column to rename
629 => Alias column0 -- ^ column to rename
@@ -635,7 +635,7 @@ renameColumn column0 column1 = UnsafeAlterTable $
635-- | An `alterColumn` alters a single column.
635-- | An `alterColumn` alters a single column.
636alterColumn
636alterColumn
637 :: ( KnownSymbol column
637 :: ( KnownSymbol column
638− , Has tab schema table0
638+ , Has tab (TablesOf schema) table0
639 , table0 ~ (constraints :=> columns)
639 , table0 ~ (constraints :=> columns)
640 , Has column columns ty0
640 , Has column columns ty0
641 , tables1 ~ (constraints :=> Alter column ty1 columns))
641 , tables1 ~ (constraints :=> Alter column ty1 columns))