Skip to content

Instantly share code, notes, and snippets.

@defp
Last active December 27, 2015 03:39
Show Gist options
  • Select an option

  • Save defp/7260865 to your computer and use it in GitHub Desktop.

Select an option

Save defp/7260865 to your computer and use it in GitHub Desktop.
beego orm demo test beego orm row query skip field
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