Exemplo n.º 1
0
func dropTables() {
	_, err := DB.DB.Exec("DROP TABLE IF EXISTS user")
	errors.Panic(err)

	_, err = DB.DB.Exec("DROP TABLE IF EXISTS user_follow")
	errors.Panic(err)
}
Exemplo n.º 2
0
func createTables() {
	dri := driver.MySQL("mysql")
	errors.Panic(
		DB.Connect(dri, dsn(dri), 1, 1),
	)

	_, err := DB.DB.Exec(`
CREATE TABLE user (
    id int AUTO_INCREMENT,
    name varchar(50) UNIQUE NOT NULL,
    age int NOT NULL DEFAULT 0,

    followings int NOT NULL DEFAULT 0,
    followers int NOT NULL DEFAULT 0,

    PRIMARY KEY(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
    `)
	errors.Panic(err)

	_, err = DB.DB.Exec(`
CREATE TABLE user_follow (
    user_id varchar(16),
    follow_user_id varchar(16),

    PRIMARY KEY(user_id, follow_user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
    `)
	errors.Panic(err)
}