func AddOrder(c *wego.WebContext) {
session := worm.NewSession()
session.ShowLog(true)
var order dao.Order
order.Create_time = time.Now().Unix()
//.....
var err error
order.Id, err = dbs.Model(&order).Insert()
if err != nil {
log.Error(err)
c.AbortWithText(510, err.Error())
return
}
c.WriteTextF(200, "%d", order.Id)
}
func main2() {
dbcnn, err := initMySql("account:pwd@tcp(127.0.0.1:3306)/db?charset=utf8&parseTime=True")
if err != nil {
log.Error(err)
}
defer dbcnn.Close()
err = worm.InitMysql(dbcnn)
if err != nil {
log.Error(err)
return
}
worm.ShowSqlLog(true)
//开启SQL语句预编译
worm.UsePrepare(true)
//设置预编译stmt缓存的最大数量
worm.SetMaxStmtCacheNum(1000)
}
func demoPrepareSession() {
session := worm.NewSession()
session.UsePrepare(true)
var user = User{Name:"name1", Age: 21, Created: time.Now()}
id, err := worm.Model(&user).Insert()
if err != nil{
log.Error(err)
return
}
_, err = worm.Model(&User{}).ID(id).Delete()
if err != nil{
log.Error(err)
return
}
}
func demoModelPrepare() {
var user = User{Name:"name1", Age: 21, Created: time.Now()}
_, err := worm.Model(&user).UsePrepare(true).Select("name", "age").ID(1).Update()
if err != nil{
log.Error(err)
return
}
}