예제 #1
0
파일: gorp.go 프로젝트: kcolls/revel-modz
func GorpInit() {
	db.Init()
	Dbm = &gorp.DbMap{Db: db.Db, Dialect: gorp.PostgresDialect{}}

	ub := Dbm.AddTable(models.UserBase{}).SetKeys(true, "UserId")
	ub.ColMap("Email").Unique = true
	setColumnSizes(ub, map[string]int{
		"UserName": 32,
		"Email":    64,
	})

	Dbm.AddTable(models.UserVolatile{}).SetKeys(true, "UserId")
	Dbm.AddTable(models.UserAuth{}).SetKeys(true, "UserId")

	Dbm.TraceOn("[gorp]", log.New(GLogger{glog.Info}, "", 0))
	Dbm.CreateTablesIfNotExists()

	if fill {
		now := time.Now().UnixNano()

		demoUser := &models.UserBase{0, "demo", "*****@*****.**"}
		errU := Dbm.Insert(demoUser)
		checkFail(errU)

		demoVolatile := &models.UserVolatile{demoUser.UserId, now, 0, 0, 0, now}
		errV := Dbm.Insert(demoVolatile)
		checkFail(errV)

		demoPassword, _ := bcrypt.GenerateFromPassword([]byte("demo"), bcrypt.DefaultCost)
		demoAuth := &models.UserAuth{demoUser.UserId, demoPassword, "", 0, 0, 0, 0}
		errA := Dbm.Insert(demoAuth)
		checkFail(errA)
	}

}
예제 #2
0
파일: gorp.go 프로젝트: joho/firesize
func InitDB() {
	db.Init()
	Dbm = &gorp.DbMap{Db: db.Db, Dialect: gorp.PostgresDialect{}}
	Dbm.AddTableWithName(models.Account{}, "accounts").SetKeys(true, "Id")
	Dbm.TraceOn("[gorp]", log.New(os.Stdout, "sql:", log.Lmicroseconds))
}