123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package Device
- import (
- "github.com/beego/beego/v2/adapter/orm"
- _ "github.com/go-sql-driver/mysql"
- )
- type DeviceSnOld struct {
- Id int `orm:"column(ID);size(11);auto;pk"`
- T_sn string `orm:"size(256);null"` // 分类
- }
- func (t *DeviceSnOld) TableName() string {
- return "device_sn_old" // 数据库名称 // ************** 替换 DesignClass **************
- }
- func init() {
- //注册模型
- orm.RegisterModel(new(DeviceSnOld))
- }
- // ---------------- 特殊方法 -------------------
- // 添加
- func Add_DeviceSnOld(T_sn string) {
- o := orm.NewOrm()
- user := DeviceSnOld{T_sn: T_sn}
- // 三个返回参数依次为:是否新创建的,对象 Id 值,错误
- o.ReadOrCreate(&user, "T_sn")
- }
- // 获取列表
- func Read_DeviceSnOld_1() (r []DeviceSnOld) {
- o := orm.NewOrm()
- // 也可以直接使用 Model 结构体作为表名
- qs := o.QueryTable(new(DeviceSnOld))
- qs.Limit(50, 0).OrderBy("-Id").All(&r)
- return r
- }
|