// ========================================================================== // This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY. // ========================================================================== package internal import ( "context" "database/sql" "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/gmvc" model2 "lims_adapter/model" "time" ) // InstrumentDao is the manager for logic model data accessing // and custom defined data operations functions management. type InstrumentDao struct { gmvc.M DB gdb.DB Table string Columns instrumentColumns } // InstrumentColumns defines and stores column names for table instrument. type instrumentColumns struct { Id string // RoomId string // 所属房间id Code string // 设备编码 Name string // 设备名称 InstrImgId string // 设备图片id InstrImgUrl string // 设备图片Url SupplierId string // 供应商 FactoryNum string // 出厂编号 Model string // 型号 Brand string // 设备品牌 InstrType string // 设备类别 Status string // 设备状态 Location string // 设备所在位置 Remark string // 备注 IsFixedPoint string // 参与点检: CalibrationAt string // 校准时间 CalibrationDeadline string // 校准使用期限 CalibrationDeadlineType string // 期限类型 MaintenCycle string // 维护周期数 CycleType string // 期限类型 HeartbeatAt string // 心跳时间 Spec string // 规格 CreatedAt string // 创建时间 CreatedBy string // 创建人 UpdatedAt string // 更新时间 UpdatedBy string // 更新人 TimeNotification string // 有效期提醒 Sharable string // 是否共享(可预约) EndTime string // 截止日期 Responsible string // 责任人 MaintenTime string // 最后维护时间 PurchaseTime string // 采购日期 JoinPlan string // 计划 IsAppoint string // 是否需要预约 DeletedAt string // 删除时间 Weekday string // 每周可预约日 BeginAt string // 预约开始时段 EndAt string // 预约结束时间 MediaIds string // 文件ID IsOpen string // 是否开启预约 1开启 2未开启 Instructions string // 使用说明 Terminal string // 信息终端 RoleId string // 自动审批角色 Sort string // 排序 } var ( // Instrument is globally public accessible object for table instrument operations. Instrument = InstrumentDao{ M: g.DB("default").Model("instrument").Safe(), DB: g.DB("default"), Table: "instrument", Columns: instrumentColumns{ Id: "Id", RoomId: "RoomId", Code: "Code", Name: "Name", InstrImgId: "InstrImgId", InstrImgUrl: "InstrImgUrl", SupplierId: "SupplierId", FactoryNum: "FactoryNum", Model: "Model", Brand: "Brand", InstrType: "InstrType", Status: "Status", Location: "Location", Remark: "Remark", IsFixedPoint: "IsFixedPoint", CalibrationAt: "CalibrationAt", CalibrationDeadline: "CalibrationDeadline", CalibrationDeadlineType: "CalibrationDeadlineType", MaintenCycle: "MaintenCycle", CycleType: "CycleType", HeartbeatAt: "HeartbeatAt", Spec: "Spec", CreatedAt: "CreatedAt", CreatedBy: "CreatedBy", UpdatedAt: "UpdatedAt", UpdatedBy: "UpdatedBy", TimeNotification: "TimeNotification", Sharable: "Sharable", EndTime: "EndTime", Responsible: "Responsible", MaintenTime: "MaintenTime", PurchaseTime: "PurchaseTime", JoinPlan: "JoinPlan", IsAppoint: "IsAppoint", DeletedAt: "DeletedAt", Weekday: "Weekday", BeginAt: "BeginAt", EndAt: "EndAt", MediaIds: "MediaIds", IsOpen: "IsOpen", Instructions: "Instructions", Terminal: "Terminal", RoleId: "RoleId", Sort: "Sort", }, } ) func NewInstrumentDao(tenant string) InstrumentDao { var dao InstrumentDao dao = InstrumentDao{ M: g.DB(tenant).Model("instrument").Safe(), DB: g.DB(tenant), Table: "instrument", Columns: instrumentColumns{ Id: "Id", RoomId: "RoomId", Code: "Code", Name: "Name", InstrImgId: "InstrImgId", InstrImgUrl: "InstrImgUrl", SupplierId: "SupplierId", FactoryNum: "FactoryNum", Model: "Model", Brand: "Brand", InstrType: "InstrType", Status: "Status", Location: "Location", Remark: "Remark", IsFixedPoint: "IsFixedPoint", CalibrationAt: "CalibrationAt", CalibrationDeadline: "CalibrationDeadline", CalibrationDeadlineType: "CalibrationDeadlineType", MaintenCycle: "MaintenCycle", CycleType: "CycleType", HeartbeatAt: "HeartbeatAt", Spec: "Spec", CreatedAt: "CreatedAt", CreatedBy: "CreatedBy", UpdatedAt: "UpdatedAt", UpdatedBy: "UpdatedBy", TimeNotification: "TimeNotification", Sharable: "Sharable", EndTime: "EndTime", Responsible: "Responsible", MaintenTime: "MaintenTime", PurchaseTime: "PurchaseTime", JoinPlan: "JoinPlan", IsAppoint: "IsAppoint", DeletedAt: "DeletedAt", Weekday: "Weekday", BeginAt: "BeginAt", EndAt: "EndAt", MediaIds: "MediaIds", IsOpen: "IsOpen", Instructions: "Instructions", Terminal: "Terminal", RoleId: "RoleId", Sort: "Sort", }, } return dao } // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy // of current DB object and with given context in it. // Note that this returned DB object can be used only once, so do not assign it to // a global or package variable for long using. func (d *InstrumentDao) Ctx(ctx context.Context) *InstrumentDao { return &InstrumentDao{M: d.M.Ctx(ctx)} } // As sets an alias name for current table. func (d *InstrumentDao) As(as string) *InstrumentDao { return &InstrumentDao{M: d.M.As(as)} } // TX sets the transaction for current operation. func (d *InstrumentDao) TX(tx *gdb.TX) *InstrumentDao { return &InstrumentDao{M: d.M.TX(tx)} } // Master marks the following operation on master node. func (d *InstrumentDao) Master() *InstrumentDao { return &InstrumentDao{M: d.M.Master()} } // Slave marks the following operation on slave node. // Note that it makes sense only if there's any slave node configured. func (d *InstrumentDao) Slave() *InstrumentDao { return &InstrumentDao{M: d.M.Slave()} } // Args sets custom arguments for model operation. func (d *InstrumentDao) Args(args ...interface{}) *InstrumentDao { return &InstrumentDao{M: d.M.Args(args...)} } // LeftJoin does "LEFT JOIN ... ON ..." statement on the model. // The parameter can be joined table and its joined condition, // and also with its alias name, like: // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid") func (d *InstrumentDao) LeftJoin(table ...string) *InstrumentDao { return &InstrumentDao{M: d.M.LeftJoin(table...)} } // RightJoin does "RIGHT JOIN ... ON ..." statement on the model. // The parameter
can be joined table and its joined condition, // and also with its alias name, like: // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid") func (d *InstrumentDao) RightJoin(table ...string) *InstrumentDao { return &InstrumentDao{M: d.M.RightJoin(table...)} } // InnerJoin does "INNER JOIN ... ON ..." statement on the model. // The parameter
can be joined table and its joined condition, // and also with its alias name, like: // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid") func (d *InstrumentDao) InnerJoin(table ...string) *InstrumentDao { return &InstrumentDao{M: d.M.InnerJoin(table...)} } // Fields sets the operation fields of the model, multiple fields joined using char ','. // The parameter can be type of string/map/*map/struct/*struct. func (d *InstrumentDao) Fields(fieldNamesOrMapStruct ...interface{}) *InstrumentDao { return &InstrumentDao{M: d.M.Fields(fieldNamesOrMapStruct...)} } // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','. // The parameter can be type of string/map/*map/struct/*struct. func (d *InstrumentDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *InstrumentDao { return &InstrumentDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)} } // Option sets the extra operation option for the model. func (d *InstrumentDao) Option(option int) *InstrumentDao { return &InstrumentDao{M: d.M.Option(option)} } // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers // the data and where attributes for empty values. func (d *InstrumentDao) OmitEmpty() *InstrumentDao { return &InstrumentDao{M: d.M.OmitEmpty()} } // Filter marks filtering the fields which does not exist in the fields of the operated table. func (d *InstrumentDao) Filter() *InstrumentDao { return &InstrumentDao{M: d.M.Filter()} } // Where sets the condition statement for the model. The parameter can be type of // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times, // multiple conditions will be joined into where statement using "AND". // Eg: // Where("uid=10000") // Where("uid", 10000) // Where("money>? AND name like ?", 99999, "vip_%") // Where("uid", 1).Where("name", "john") // Where("status IN (?)", g.Slice{1,2,3}) // Where("age IN(?,?)", 18, 50) // Where(User{ Id : 1, UserName : "john"}) func (d *InstrumentDao) Where(where interface{}, args ...interface{}) *InstrumentDao { return &InstrumentDao{M: d.M.Where(where, args...)} } // WherePri does the same logic as M.Where except that if the parameter // is a single condition like int/string/float/slice, it treats the condition as the primary // key value. That is, if primary key is "id" and given parameter as "123", the // WherePri function treats the condition as "id=123", but M.Where treats the condition // as string "123". func (d *InstrumentDao) WherePri(where interface{}, args ...interface{}) *InstrumentDao { return &InstrumentDao{M: d.M.WherePri(where, args...)} } // And adds "AND" condition to the where statement. func (d *InstrumentDao) And(where interface{}, args ...interface{}) *InstrumentDao { return &InstrumentDao{M: d.M.And(where, args...)} } // Or adds "OR" condition to the where statement. func (d *InstrumentDao) Or(where interface{}, args ...interface{}) *InstrumentDao { return &InstrumentDao{M: d.M.Or(where, args...)} } // Group sets the "GROUP BY" statement for the model. func (d *InstrumentDao) Group(groupBy string) *InstrumentDao { return &InstrumentDao{M: d.M.Group(groupBy)} } // Order sets the "ORDER BY" statement for the model. func (d *InstrumentDao) Order(orderBy ...string) *InstrumentDao { return &InstrumentDao{M: d.M.Order(orderBy...)} } // Limit sets the "LIMIT" statement for the model. // The parameter can be either one or two number, if passed two number is passed, // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]" // statement. func (d *InstrumentDao) Limit(limit ...int) *InstrumentDao { return &InstrumentDao{M: d.M.Limit(limit...)} } // Offset sets the "OFFSET" statement for the model. // It only makes sense for some databases like SQLServer, PostgreSQL, etc. func (d *InstrumentDao) Offset(offset int) *InstrumentDao { return &InstrumentDao{M: d.M.Offset(offset)} } // Page sets the paging number for the model. // The parameter is started from 1 for paging. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement. func (d *InstrumentDao) Page(page, limit int) *InstrumentDao { return &InstrumentDao{M: d.M.Page(page, limit)} } // Batch sets the batch operation number for the model. func (d *InstrumentDao) Batch(batch int) *InstrumentDao { return &InstrumentDao{M: d.M.Batch(batch)} } // Cache sets the cache feature for the model. It caches the result of the sql, which means // if there's another same sql request, it just reads and returns the result from cache, it // but not committed and executed into the database. // // If the parameter < 0, which means it clear the cache with given . // If the parameter = 0, which means it never expires. // If the parameter > 0, which means it expires after . // // The optional parameter is used to bind a name to the cache, which means you can later // control the cache like changing the or clearing the cache with specified . // // Note that, the cache feature is disabled if the model is operating on a transaction. func (d *InstrumentDao) Cache(duration time.Duration, name ...string) *InstrumentDao { return &InstrumentDao{M: d.M.Cache(duration, name...)} } // Data sets the operation data for the model. // The parameter can be type of string/map/gmap/slice/struct/*struct, etc. // Eg: // Data("uid=10000") // Data("uid", 10000) // Data(g.Map{"uid": 10000, "name":"john"}) // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"}) func (d *InstrumentDao) Data(data ...interface{}) *InstrumentDao { return &InstrumentDao{M: d.M.Data(data...)} } // All does "SELECT FROM ..." statement for the model. // It retrieves the records from table and returns the result as []*model.Instrument. // It returns nil if there's no record retrieved with the given conditions from table. // // The optional parameter is the same as the parameter of M.Where function, // see M.Where. func (d *InstrumentDao) All(where ...interface{}) ([]*model2.Instrument, error) { all, err := d.M.All(where...) if err != nil { return nil, err } var entities []*model2.Instrument if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows { return nil, err } return entities, nil } // One retrieves one record from table and returns the result as *model.Instrument. // It returns nil if there's no record retrieved with the given conditions from table. // // The optional parameter is the same as the parameter of M.Where function, // see M.Where. func (d *InstrumentDao) One(where ...interface{}) (*model2.Instrument, error) { one, err := d.M.One(where...) if err != nil { return nil, err } var entity *model2.Instrument if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows { return nil, err } return entity, nil } // FindOne retrieves and returns a single Record by M.WherePri and M.One. // Also see M.WherePri and M.One. func (d *InstrumentDao) FindOne(where ...interface{}) (*model2.Instrument, error) { one, err := d.M.FindOne(where...) if err != nil { return nil, err } var entity *model2.Instrument if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows { return nil, err } return entity, nil } // FindAll retrieves and returns Result by by M.WherePri and M.All. // Also see M.WherePri and M.All. func (d *InstrumentDao) FindAll(where ...interface{}) ([]*model2.Instrument, error) { all, err := d.M.FindAll(where...) if err != nil { return nil, err } var entities []*model2.Instrument if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows { return nil, err } return entities, nil } // Struct retrieves one record from table and converts it into given struct. // The parameter should be type of *struct/**struct. If type **struct is given, // it can create the struct internally during converting. // // The optional parameter is the same as the parameter of Model.Where function, // see Model.Where. // // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions // from table and is not nil. // // Eg: // user := new(User) // err := dao.User.Where("id", 1).Struct(user) // // user := (*User)(nil) // err := dao.User.Where("id", 1).Struct(&user) func (d *InstrumentDao) Struct(pointer interface{}, where ...interface{}) error { return d.M.Struct(pointer, where...) } // Structs retrieves records from table and converts them into given struct slice. // The parameter should be type of *[]struct/*[]*struct. It can create and fill the struct // slice internally during converting. // // The optional parameter is the same as the parameter of Model.Where function, // see Model.Where. // // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions // from table and is not empty. // // Eg: // users := ([]User)(nil) // err := dao.User.Structs(&users) // // users := ([]*User)(nil) // err := dao.User.Structs(&users) func (d *InstrumentDao) Structs(pointer interface{}, where ...interface{}) error { return d.M.Structs(pointer, where...) } // Scan automatically calls Struct or Structs function according to the type of parameter . // It calls function Struct if is type of *struct/**struct. // It calls function Structs if is type of *[]struct/*[]*struct. // // The optional parameter is the same as the parameter of Model.Where function, // see Model.Where. // // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil. // // Eg: // user := new(User) // err := dao.User.Where("id", 1).Scan(user) // // user := (*User)(nil) // err := dao.User.Where("id", 1).Scan(&user) // // users := ([]User)(nil) // err := dao.User.Scan(&users) // // users := ([]*User)(nil) // err := dao.User.Scan(&users) func (d *InstrumentDao) Scan(pointer interface{}, where ...interface{}) error { return d.M.Scan(pointer, where...) } // Chunk iterates the table with given size and callback function. func (d *InstrumentDao) Chunk(limit int, callback func(entities []*model2.Instrument, err error) bool) { d.M.Chunk(limit, func(result gdb.Result, err error) bool { var entities []*model2.Instrument err = result.Structs(&entities) if err == sql.ErrNoRows { return false } return callback(entities, err) }) } // LockUpdate sets the lock for update for current operation. func (d *InstrumentDao) LockUpdate() *InstrumentDao { return &InstrumentDao{M: d.M.LockUpdate()} } // LockShared sets the lock in share mode for current operation. func (d *InstrumentDao) LockShared() *InstrumentDao { return &InstrumentDao{M: d.M.LockShared()} } // Unscoped enables/disables the soft deleting feature. func (d *InstrumentDao) Unscoped() *InstrumentDao { return &InstrumentDao{M: d.M.Unscoped()} }