beego的orm包操作mysql数据库

package models

import (
	_ "github.com/go-sql-driver/mysql"
	"github.com/astaxie/beego/orm"
	"time"
)

type User struct {
	Id int
	Name string
	Pwd string
}
type Child struct {
	Id int
	Num int
}

type Father struct {
	Id int
	Name string
}
type Article struct {
	Id int `orm:"pk;auto"`
	Title string `orm:"unique;size(40)"`
	Content string `orm:"size(500)"`
	Img string	`orm:"null"`
	Time time.Time `orm:"type(datetime);auto_now_add"`
	ReadCount int `orm:"default(0)"`
}
func init(){
	orm.RegisterDataBase("default","mysql","root:123456@tcp(127.0.0.1:3306)/test430")
	orm.RegisterModel(new(User),new(Article))
	orm.RunSyncdb("default",false,true)
}
func main(){
    o := orm.New()
    article := Article{1}
    O.Insert(&article)
}

猜你喜欢

转载自blog.csdn.net/u013755520/article/details/89966760