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", 30) // 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) }
网名:浩秦;
邮箱:root#landv.pw;
博客:landv.cnblogs.com;
只要我能控制一個國家的貨幣發行,我不在乎誰制定法律。金錢一旦作響,壞話隨之戛然而止。