bur
An ORM framework implementation in Go(based on sg).
Quickstart
package main
import (
"database/sql"
"fmt"
. "github.com/go-the-way/bur"
"github.com/go-the-way/sg"
_ "github.com/go-sql-driver/mysql"
)
const (
testDriverName = "mysql"
testDSN = "root:oGMyxw4auP6F6Sn1ENxMVTa1kCc=@tcp(192.168.0.252:3310)/test"
)
var (
testDB, _ = sql.Open(testDriverName, testDSN)
)
type userModel struct {
ID int `orm:"pk{T} column{id} insertIgnore{T} definition{id int not null auto_increment comment 'ID'}"`
Name string `orm:"pk{F} column{name} definition{name varchar(50) not null default 'hello world' comment 'Name'}"`
Age int `orm:"pk{F} column{age} definition{age int not null default '20' comment 'Age'}"`
Address string `orm:"pk{F} column{address} definition{address varchar(100) not null comment 'Address'}"`
Phone string `orm:"pk{F} column{phone} definition{phone varchar(11) not null default '13900000000' comment 'Phone'}"`
CreateTime string `orm:"pk{F} column{create_time} insertIgnore{T} updateIgnore{T} definition{create_time datetime not null default current_timestamp comment 'CreateTime'}"`
XYZ string `orm:"pk{F} column{xyz} definition{xyz varchar(50) not null default 'xyz' comment 'XYZ'}"`
}
func (u *userModel) MetaData() *ModelMeta {
return &ModelMeta{
Migrate: true,
Comment: "The userModel Table",
IndexDefinitions: []sg.Ge{
sg.IndexDefinition(false, sg.P("idx_name"), sg.C("name")),
},
InsertIgnores: []sg.C{"id", "create_time"},
}
}
func main() {
DS(testDB)
Register(new(userModel))
o := New(new(userModel))
count, err := o.Select().Count(&userModel{ID: 1})
if err != nil {
fmt.Println(err)
} else {
fmt.Println("count = ", count)
}
}