示例#1
0
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)
}
示例#2
0
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)
}
示例#3
0
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)
}
示例#4
0
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
		}
	}
}
示例#5
0
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] + "')")
		}
	}
}
示例#6
0
func DropTable(table string) {
	query := "DROP TABLE " + table
	connector.Query(query)
}
示例#7
0
func RemoveIndex(table, index_name string) {
	query := "DROP INDEX " + index_name + " ON " + table
	fmt.Println(query)
	connector.Query(query)
}
示例#8
0
func RemoveForeigKey(this ColumnBuilder) {
	query := "ALTER TABLE" + this.Name + "DROP FOREIGN KEY" + this.ForeignKey
	connector.Query(query)
}
示例#9
0
func AddForeignKey(col1 ColumnBuilder, col2 ColumnBuilder) {
	query := "ALTER " + col1.Table + "ADD FOREIGN KEY (" + col1.ForeignKey + ")"
	query += "RERERENCES " + col2.Table + "(" + col2.ForeignKey + ")"
	connector.Query(query)
}
示例#10
0
func AddIndex(table, index_name, column string) {
	query := "CREATE INDEX " + index_name + " ON " + table + "(" + column + ")"
	connector.Query(query)
}
示例#11
0
func RemoveColumn(table, column string) {
	query := "ALTER TABLE " + table + " DROP COLUMN " + column
	connector.Query(query)
}