Last active
December 27, 2015 03:39
-
-
Save defp/7260865 to your computer and use it in GitHub Desktop.
beego orm demo test beego orm row query skip field
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 posts []Post | |
| num, err := o.Raw("SELECT * from post where id > ?", 0).QueryRows(&posts) | |
| if err != nil { | |
| fmt.Println(err) | |
| } | |
| fmt.Println(num) | |
| fmt.Println(posts) | |
| } | |
| /* | |
| CREATE TABLE `post` ( | |
| `id` int(11) NOT NULL AUTO_INCREMENT, | |
| `title` varchar(255) NOT NULL, | |
| PRIMARY KEY (`id`) | |
| ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment