func AddColum(table string, this ColumnBuilder) { acceptValues := []string{"nvarchar", "varchar"} query := "ALTER TABLE " + table + " ADD COLUMN " + this.Name + " " + this.Data_type + "" if Contains(acceptValues, this.Data_type) { if this.Length <= 0 { this.Length = 255 } query += "(" + strconv.Itoa(this.Length) + ")" } connector.Query(query) }
func CreateTable(table_name string, columns []ColumnBuilder) { query := "CREATE TABLE " + table_name + "(" for index, column := range columns { query += column.creation_string() if index < (len(columns) - 1) { query += "," } } query += ")" connector.Query(query) }
func ChangeColumn(table string, column ColumnBuilder) { var modifier string if column.New_name != "" { modifier = "CHANGE" } else { modifier = "MODIFY" } query := "ALTER TABLE " + table + " " + modifier + " " + column.creation_string() connector.Query(query) }
func (this Migrin) down() { files, _ := ioutil.ReadDir(initFolderNameMigrationDown) for _, f := range files { name_components := strings.Split(f.Name(), "_") if len(name_components) > 0 && migration_executed(name_components[0]) { execute_migration(f, initFolderNameMigrationDown) connector.Query("DELETE FROM migrations WHERE migration_id = '" + name_components[0] + "'") break } } }
func (this Migrin) up() { this.create_migrations_table() files, _ := ioutil.ReadDir(initFolderNameMigration) for _, f := range files { extension := strings.Split(f.Name(), ".") if len(extension) < 1 || extension[len(extension)-1] != "go" { continue } name_components := strings.Split(f.Name(), "_") if len(name_components) > 0 && !migration_executed(name_components[0]) { execute_migration(f, initFolderNameMigration) connector.Query("INSERT INTO migrations(migration_id) VALUES('" + name_components[0] + "')") } } }
func DropTable(table string) { query := "DROP TABLE " + table connector.Query(query) }
func RemoveIndex(table, index_name string) { query := "DROP INDEX " + index_name + " ON " + table fmt.Println(query) connector.Query(query) }
func RemoveForeigKey(this ColumnBuilder) { query := "ALTER TABLE" + this.Name + "DROP FOREIGN KEY" + this.ForeignKey connector.Query(query) }
func AddForeignKey(col1 ColumnBuilder, col2 ColumnBuilder) { query := "ALTER " + col1.Table + "ADD FOREIGN KEY (" + col1.ForeignKey + ")" query += "RERERENCES " + col2.Table + "(" + col2.ForeignKey + ")" connector.Query(query) }
func AddIndex(table, index_name, column string) { query := "CREATE INDEX " + index_name + " ON " + table + "(" + column + ")" connector.Query(query) }
func RemoveColumn(table, column string) { query := "ALTER TABLE " + table + " DROP COLUMN " + column connector.Query(query) }