@@ -158,6 +158,7 @@ newtype TableConstraint
158-- "CREATE TABLE tab (a int NOT NULL, b int NOT NULL, CHECK ((a > b)));"
158-- "CREATE TABLE tab (a int NOT NULL, b int NOT NULL, CHECK ((a > b)));"
160 :: Condition '[table ::: columns] 'Ungrouped '[]
160 :: Condition '[table ::: columns] 'Ungrouped '[]
161+ -- ^ condition to check
161 -> TableConstraint schema columns
162 -> TableConstraint schema columns
162check condition = UnsafeTableConstraint $
163check condition = UnsafeTableConstraint $
163 "CHECK" <+> parenthesized (renderExpression condition)
164 "CHECK" <+> parenthesized (renderExpression condition)
@@ -176,6 +177,7 @@ check condition = UnsafeTableConstraint $
177 :: SListI subcolumns
178 :: SListI subcolumns
178 => NP (Column columns) subcolumns
179 => NP (Column columns) subcolumns
180+ -- ^ unique column or group of columns
179 -> TableConstraint schema columns
181 -> TableConstraint schema columns
180unique columns = UnsafeTableConstraint $
182unique columns = UnsafeTableConstraint $
181 "UNIQUE" <+> parenthesized (renderCommaSeparated renderColumn columns)
183 "UNIQUE" <+> parenthesized (renderCommaSeparated renderColumn columns)
@@ -307,7 +309,7 @@ DROP statements
307-- "DROP TABLE muh_table;"
309-- "DROP TABLE muh_table;"
309 :: KnownSymbol table
311 :: KnownSymbol table
310− => Alias table
312+ => Alias table -- ^ table to remove
311 -> Definition schema (Drop table schema)
313 -> Definition schema (Drop table schema)
312dropTable table = UnsafeDefinition $ "DROP TABLE" <+> renderAlias table <> ";"
314dropTable table = UnsafeDefinition $ "DROP TABLE" <+> renderAlias table <> ";"
@@ -333,8 +335,8 @@ alterTable table alteration = UnsafeDefinition $
333-- "ALTER TABLE foo RENAME TO bar;"
335-- "ALTER TABLE foo RENAME TO bar;"
334alterTableRename
336alterTableRename
335 :: (KnownSymbol table0, KnownSymbol table1)
337 :: (KnownSymbol table0, KnownSymbol table1)
336− => Alias table0
338+ => Alias table0 -- ^ table to rename
337− -> Alias table1
339+ -> Alias table1 -- ^ what to rename it
338 -> Definition schema (Rename table0 table1 schema)
340 -> Definition schema (Rename table0 table1 schema)
339alterTableRename table0 table1 = UnsafeDefinition $
341alterTableRename table0 table1 = UnsafeDefinition $
340 "ALTER TABLE" <+> renderAlias table0
342 "ALTER TABLE" <+> renderAlias table0
@@ -353,8 +355,8 @@ alterTableRename table0 table1 = UnsafeDefinition $
353-- "ALTER TABLE tab ADD CHECK ((col > 0));"
355-- "ALTER TABLE tab ADD CHECK ((col > 0));"
354alterTableAddConstraint
356alterTableAddConstraint
355 :: HasTable table schema columns
357 :: HasTable table schema columns
356− => Alias table
358+ => Alias table -- ^ table to constrain
357− -> TableConstraint schema columns
359+ -> TableConstraint schema columns -- ^ what constraint to add
358 -> Definition schema schema
360 -> Definition schema schema
359alterTableAddConstraint table constraint = UnsafeDefinition $
361alterTableAddConstraint table constraint = UnsafeDefinition $
360 "ALTER TABLE" <+> renderAlias table
362 "ALTER TABLE" <+> renderAlias table
@@ -407,8 +409,8 @@ addColumnDefault column ty = UnsafeAlterColumns $
407-- "ALTER TABLE tab ADD COLUMN col2 text;"
409-- "ALTER TABLE tab ADD COLUMN col2 text;"
408addColumnNull
410addColumnNull
409 :: KnownSymbol column
411 :: KnownSymbol column
410− => Alias column
412+ => Alias column -- ^ column to add
411− -> TypeExpression ('Required ('Null ty))
413+ -> TypeExpression ('Required ('Null ty)) -- ^ type of the new column
412 -> AlterColumns columns (Create column ('Required ('Null ty)) columns)
414 -> AlterColumns columns (Create column ('Required ('Null ty)) columns)
413addColumnNull column ty = UnsafeAlterColumns $
415addColumnNull column ty = UnsafeAlterColumns $
414 "ADD COLUMN" <+> renderAlias column <+> renderTypeExpression ty
416 "ADD COLUMN" <+> renderAlias column <+> renderTypeExpression ty
@@ -431,7 +433,7 @@ addColumnNull column ty = UnsafeAlterColumns $
431-- "ALTER TABLE tab DROP COLUMN col2;"
433-- "ALTER TABLE tab DROP COLUMN col2;"
432dropColumn
434dropColumn
433 :: KnownSymbol column
435 :: KnownSymbol column
434− => Alias column
436+ => Alias column -- ^ column to remove
435 -> AlterColumns columns (Drop column columns)
437 -> AlterColumns columns (Drop column columns)
436dropColumn column = UnsafeAlterColumns $
438dropColumn column = UnsafeAlterColumns $
437 "DROP COLUMN" <+> renderAlias column
439 "DROP COLUMN" <+> renderAlias column
@@ -452,7 +454,7 @@ dropColumn column = UnsafeAlterColumns $
452-- "ALTER TABLE tab DROP COLUMN col2 CASCADE;"
454-- "ALTER TABLE tab DROP COLUMN col2 CASCADE;"
453dropColumnCascade
455dropColumnCascade
454 :: KnownSymbol column
456 :: KnownSymbol column
455− => Alias column
457+ => Alias column -- ^ column to remove
456 -> AlterColumns columns (Drop column columns)
458 -> AlterColumns columns (Drop column columns)
457dropColumnCascade column = UnsafeAlterColumns $
459dropColumnCascade column = UnsafeAlterColumns $
458 "DROP COLUMN" <+> renderAlias column <+> "CASCADE"
460 "DROP COLUMN" <+> renderAlias column <+> "CASCADE"
@@ -479,8 +481,8 @@ renameColumn column0 column1 = UnsafeAlterColumns $
479-- | An `alterColumn` alters a single column.
481-- | An `alterColumn` alters a single column.
480alterColumn
482alterColumn
481 :: (KnownSymbol column, HasColumn column columns ty0)
483 :: (KnownSymbol column, HasColumn column columns ty0)
482− => Alias column
484+ => Alias column -- ^ column to alter
483− -> AlterColumn ty0 ty1
485+ -> AlterColumn ty0 ty1 -- ^ alteration to perform
484 -> AlterColumns columns (Alter column columns ty1)
486 -> AlterColumns columns (Alter column columns ty1)
485alterColumn column alteration = UnsafeAlterColumns $
487alterColumn column alteration = UnsafeAlterColumns $
486 "ALTER COLUMN" <+> renderAlias column <+> renderAlterColumn alteration
488 "ALTER COLUMN" <+> renderAlias column <+> renderAlterColumn alteration
@@ -504,7 +506,7 @@ newtype AlterColumn (ty0 :: ColumnType) (ty1 :: ColumnType) =
505-- "ALTER TABLE tab ALTER COLUMN col SET DEFAULT 5;"
507-- "ALTER TABLE tab ALTER COLUMN col SET DEFAULT 5;"
506setDefault
508setDefault
507− :: Expression '[] 'Ungrouped '[] ('Required ty)
509+ :: Expression '[] 'Ungrouped '[] ('Required ty) -- ^ default value to set
508 -> AlterColumn (optionality ty) ('Optional ty)
510 -> AlterColumn (optionality ty) ('Optional ty)
509setDefault expression = UnsafeAlterColumn $
511setDefault expression = UnsafeAlterColumn $
510 "SET DEFAULT" <+> renderExpression expression
512 "SET DEFAULT" <+> renderExpression expression
@@ -536,8 +538,7 @@ dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
536-- in renderDefinition definition
538-- in renderDefinition definition
538-- "ALTER TABLE tab ALTER COLUMN col SET NOT NULL;"
540-- "ALTER TABLE tab ALTER COLUMN col SET NOT NULL;"
540− :: AlterColumn (optionality ('Null ty)) (optionality ('NotNull ty))
541+setNotNull :: AlterColumn (optionality ('Null ty)) (optionality ('NotNull ty))
541setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
542setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
543-- | A `dropNotNull` drops a @NOT NULL@ constraint from a column.
544-- | A `dropNotNull` drops a @NOT NULL@ constraint from a column.
@@ -551,8 +552,7 @@ setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
551-- in renderDefinition definition
552-- in renderDefinition definition
553-- "ALTER TABLE tab ALTER COLUMN col DROP NOT NULL;"
554-- "ALTER TABLE tab ALTER COLUMN col DROP NOT NULL;"
555− :: AlterColumn (optionality ('NotNull ty)) (optionality ('Null ty))
555+dropNotNull :: AlterColumn (optionality ('NotNull ty)) (optionality ('Null ty))
556dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
556dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
558-- | An `alterType` converts a column to a different data type.
558-- | An `alterType` converts a column to a different data type.