func initTestDB(t *testing.T) *gorp.DbMap { setenvMySQL() mysql := gumspecs.ReadMySQL() sqlDB, err := mysql.DB() if err != nil { t.Fatal(err) } db := &gorp.DbMap{ Db: sqlDB, Dialect: gorp.MySQLDialect{"InnoDB", "UTF8"}, } db.AddTableWithName(User{}, UserTable).SetKeys(true, "id") err = db.DropTablesIfExists() if err != nil { t.Fatal(err) } err = db.CreateTablesIfNotExists() if err != nil { t.Fatal(err) } return db }
func TestCreateTable(t *testing.T) { setenvMySQL() mysql := gumspecs.ReadMySQL() db, err := mysql.DB() if err != nil { t.Fatal(err) } err = CreateTables(db) if err != nil { t.Fatal(err) } }
func TestAddTablesGorp(t *testing.T) { setenvMySQL() mysql := gumspecs.ReadMySQL() db, err := mysql.DB() if err != nil { t.Fatal(err) } dbMap := &gorp.DbMap{ Db: db, Dialect: gorp.MySQLDialect{ "UTF8", "InnoDB", }, } AddTables(dbMap) }
func main() { gumspecs.AppName = "tasks" srv := gumspecs.ReadHTTPServer() mysql := gumspecs.ReadMySQL() sqlDB, err := mysql.DB() if err != nil { log.Fatal(err) } db := &gorp.DbMap{ Db: sqlDB, Dialect: gorp.MySQLDialect{ "InnonDB", "UTF8", }, } router := gin.New() s2tore := smem.NewStore() signedIn := gumauth.SignedIn(&s2tore) tasksAPI := router.Group("/v1/tasks") { g := gumwrap.Gorp tasksAPI.GET("/", signedIn(g(tasks.ReadAll, db))) tasksAPI.GET("/:id", signedIn(g(tasks.ReadOne, db))) tasksAPI.POST("/", signedIn(g(tasks.Create, db))) tasksAPI.PUT("/:id", signedIn(g(tasks.Update, db))) tasksAPI.DELETE("/:id", signedIn(g(tasks.Delete, db))) } uStore := gumauth.SQLUserStore{db.Db} router.POST("/signin/:name/:password", gumauth.SignIn(&s2tore, uStore)) router.POST("/signup", gumauth.CreateUserSQL(db.Db)) router.Run(srv.String()) }
func initTestDB(t *testing.T) *gorp.DbMap { setenvMySQL() mysql := gumspecs.ReadMySQL() sqlDB, err := mysql.DB() if err != nil { t.Fatal(err) } db := GorpInit(sqlDB) err = db.DropTablesIfExists() if err != nil { t.Fatal(err) } err = db.CreateTables() if err != nil { t.Fatal(err) } return db }