Created
November 28, 2013 09:47
-
-
Save defp/7689519 to your computer and use it in GitHub Desktop.
beego orm test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "github.com/astaxie/beego/orm" | |
| _ "github.com/go-sql-driver/mysql" | |
| ) | |
| type Post struct { | |
| Id int | |
| Title string | |
| IsUpdated bool `orm:"-"` | |
| } | |
| func init() { | |
| orm.RegisterDriver("mysql", orm.DR_MySQL) | |
| orm.RegisterDataBase("default", "mysql", "root:root@/test?charset=utf8") | |
| } | |
| func main() { | |
| o := orm.NewOrm() | |
| o.Using("default") // 默认使用 default,你可以指定为其他数据库 | |
| var sql string = "INSERT INTO new_item_pack (role_uid,role_id,item_uid,item_id,count,type,pack_index,is_lock,is_deleted) VALUES (?,?,?,?,?,?,?,?,?) " | |
| result, err := o.Raw(sql, "item.Role_uid", 3, 4,3, 5, 6, 7, 8, true).Exec() | |
| if err != nil { | |
| fmt.Println(err) | |
| } | |
| id, _ := result.LastInsertId() | |
| fmt.Println(id) | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment