@@ -736,17 +736,118 @@ createTable (Alias table) columns = UnsafeStatement $ mconcat
736DROP statements
736DROP statements
737-----------------------------------------}
737-----------------------------------------}
739−class KnownSymbol table => DropTable table schema0 schema1
740+ :: KnownSymbol table
740− | table schema0 -> schema1 where
741+ => Alias table
741− dropTable :: Alias table -> Statement '[] '[] schema0 schema1
742+ -> Statement '[] '[] schema (Drop table schema)
742− dropTable (Alias table) = UnsafeStatement $
743+dropTable (Alias table) = UnsafeStatement $
743− "DROP TABLE " <> fromString (symbolVal' table) <> ";"
744+ "DROP TABLE " <> fromString (symbolVal' table) <> ";"
744−instance {-# OVERLAPPING #-}
745+
745− (KnownSymbol table, table ~ table', schema ~ schema')
746+{-----------------------------------------
746− => DropTable table ((table' ::: columns) ': schema) schema'
747+ALTER statements
747−instance {-# OVERLAPPABLE #-}
748+-----------------------------------------}
748− DropTable table schema0 schema1
749+
749− => DropTable table (table' ': schema0) (table' ': schema1)
750+alterTable
751+ :: HasTable table schema columns0
753+ -> AlterTable columns0 columns1
754+ -> Statement '[] '[] schema (Alter table schema columns1)
755+alterTable (Alias table) alteration = UnsafeStatement $
757+ <> fromString (symbolVal' table)
759+ <> renderAlterTable alteration
763+ :: (KnownSymbol table0, KnownSymbol table1)
766+ -> Statement '[] '[] schema (Rename table0 table1 schema)
767+alterTableRename (Alias table0) (Alias table1) = UnsafeStatement $
769+ <> fromString (symbolVal' table0)
771+ <> fromString (symbolVal' table1)
775+ (columns0 :: [(Symbol, ColumnType)])
776+ (columns1 :: [(Symbol, ColumnType)]) =
777+ UnsafeAlterTable {renderAlterTable :: ByteString}
780+ :: KnownSymbol column
782+ -> TypeExpression ('Optional ty)
783+ -> AlterTable columns ((column ::: 'Optional ty) ': columns)
784+addColumnDefault (Alias column) ty = UnsafeAlterTable $
786+ <> fromString (symbolVal' column)
788+ <> renderTypeExpression ty
791+ :: KnownSymbol column
793+ -> TypeExpression ('Required ('Null ty))
794+ -> AlterTable columns ((column ::: 'Required ('Null ty)) ': columns)
795+addColumnNull (Alias column) ty = UnsafeAlterTable $
797+ <> fromString (symbolVal' column)
799+ <> renderTypeExpression ty
802+ :: KnownSymbol column
804+ -> AlterTable columns (Drop column columns)
805+dropColumn (Alias column) = UnsafeAlterTable $
806+ "DROP COLUMN " <> fromString (symbolVal' column)
809+ :: (KnownSymbol column0, KnownSymbol column1)
812+ -> AlterTable columns (Rename column0 column1 columns)
813+renameColumn (Alias column0) (Alias column1) = UnsafeAlterTable $
814+ "RENAME COLUMN " <> fromString (symbolVal' column0)
815+ <> " TO " <> fromString (symbolVal' column1)
818+ :: (KnownSymbol column, HasColumn column columns ty0)
820+ -> AlterColumn ty0 ty1
821+ -> AlterTable columns (Alter column columns ty1)
822+alterColumn (Alias column) alteration = UnsafeAlterTable $
823+ "ALTER COLUMN " <> fromString (symbolVal' column)
824+ <> " " <> renderAlterColumn alteration
826+data AlterColumn (ty0 :: ColumnType) (ty1 :: ColumnType) =
827+ UnsafeAlterColumn {renderAlterColumn :: ByteString}
830+ :: Expression '[] '[] ('Required ty)
831+ -> AlterColumn ('Required ty) ('Optional ty)
832+setDefault expression = UnsafeAlterColumn $
833+ "SET DEFAULT " <> renderExpression expression
835+dropDefault :: AlterColumn ('Optional ty) ('Required ty)
836+dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
839+ :: AlterColumn (optionality ('Null ty)) (optionality ('NotNull ty))
840+setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
843+ :: AlterColumn (optionality ('NotNull ty)) (optionality ('Null ty))
844+dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
848+ => TypeExpression (optionality (nullity ty1))
849+ -> AlterColumn (optionality (nullity ty0)) (optionality (nullity ty1))
850+alterType ty = UnsafeAlterColumn $ "TYPE " <> renderTypeExpression ty
751{-----------------------------------------
852{-----------------------------------------
752INSERT statements
853INSERT statements