// Copyright 2019 autocareai.com. All rights reserved. // Use of this source code is governed by autocareai.com. package model import ( "github.com/jinzhu/gorm" "time" ) type TProviderDevice struct { Id int64 `gorm:"column:id" json:"id" form:"id"` ProviderId int64 `gorm:"column:provider_id" json:"provider_id" form:"provider_id"` DeviceCode int32 `gorm:"column:device_code" json:"device_code" form:"device_code"` Status int32 `gorm:"column:status" json:"status" form:"status"` CreatedAt time.Time UpdatedAt time.Time } func (TProviderDevice) TableName() string { return "t_provider_device" } func (p *TProviderDevice) Insert(db *gorm.DB) error { return db.Create(p).Error } func (p *TProviderDevice) Find(db *gorm.DB, where map[string]interface{}) error { cond, val, err := whereBuild(where) if err != nil { return err } return db.Table(p.TableName()).Where(cond, val...).First(p).Error } func (p *TProviderDevice) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error { cond, val, err := whereBuild(where) if err != nil { return err } return db.Table(p.TableName()).Table(p.TableName()).Where(cond, val...).Updates(values).Error } func (p *TProviderDevice) FindSort(db *gorm.DB, where map[string]interface{}, sort string) error { cond, val, err := whereBuild(where) if err != nil { return err } ps := []TProviderDevice{} err = db.Table(p.TableName()).Where(cond, val...).Order(sort).Limit(1).Find(&ps).Error if err != nil { return err } if len(ps) > 0 { *p = ps[0] } return nil } func (p *TProviderDevice) Save(db *gorm.DB) error { return db.Save(p).Error } func (p *TProviderDevice) List(db *gorm.DB, where map[string]interface{}) (list []TProviderDevice, err error) { if len(where) > 0 { cond, val, err := whereBuild(where) if err != nil { return list, err } result := db.Table(p.TableName()).Where(cond, val...).Find(&list) return list, result.Error } result := db.Table(p.TableName()).Find(&list) return list, result.Error } func (p *TProviderDevice) All(db *gorm.DB) (list []TProviderDevice, err error) { result := db.Table(p.TableName()).Find(&list) return list, result.Error } func (p *TProviderDevice) Count(db *gorm.DB, where map[string]interface{}) (int64, error) { if len(where) > 0 { cond, val, err := whereBuild(where) if err != nil { return 0, err } ret := int64(0) err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error return ret, err } ret := int64(0) err := db.Table(p.TableName()).Count(&ret).Error return ret, err } func (p *TProviderDevice) Del(db *gorm.DB, where map[string]interface{}) error { cond, val, err := whereBuild(where) if err != nil { return err } return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error }