golang orm

package main

import (
"fmt"
"github.com/astaxie/beego/orm"
_"github.com/go-sql-driver/mysql"
) type User struct{
Id int
Name string `orm:"size(100)"`
Fuck string
Admin int
} func init() {
// set default database
orm.RegisterDataBase("default", "mysql", "root:root@tcp(127.0.0.1:3306)/fuck?charset=utf8", ) // register model
orm.RegisterModel(new(User)) // create table
orm.RunSyncdb("default", false, true)
}
func main() {
o :=orm.NewOrm() user:=User{Name:"slene"}
id,err :=o.Insert(&user)
fmt.Printf("ID:%d,ERR:%v\n",id,err) user.Name="astaxie"
num,err:=o.Update(&user)
fmt.Printf("NUM:%d,ERR:%v\n",num,err) // read one
u := User{Id: user.Id}
err = o.Read(&u)
fmt.Printf("ERR: %v\n", err) fmt.Println("------------------")
var maps []orm.Params
num, err = o.Raw("SELECT * FROM user").Values(&maps)
for _,term := range maps{
fmt.Println(term["id"],":",term["name"],term["fuck"])
} //// delete
//num, err = o.Delete(&u)
//fmt.Printf("NUM: %d, ERR: %v\n", num, err)
}
上一篇:React组件绑定this的三种方法


下一篇:[ArcGIS所需的补丁]ArcGIS 10.2.2 for Desktop联系Oracle(2014年10上个月发布)数据库崩溃