Exemplo n.º 1
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)
}
Exemplo n.º 2
0
func TestError(t *testing.T) {
	tt := testing2.Wrap(t)
	mysql := driver.MySQL("mysql")

	err := errors.Err(`Duplicate entry '14d1b6c34a001-1648e0754a001' for key 'PRIMARY'`) // for combined primary key
	tt.Eq(mysql.PrimaryKey(), mysql.DuplicateKey(err))

	err = errors.Err("CONSTRAINT `article_vote_ibfk_1` FOREIGN KEY (`article_id`) REFERENCES `article` (`article_id`)")
	tt.Eq("article_id", mysql.ForeignKey(err))
}