sqlDB

package
v0.0.0-...-8415a54 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(tab interface{}, query string, where ...interface{}) (count int64)

查询某个表符合条件的总数,query参数为空字符串则查询整个表的总数,否则为按条件查询

func Create

func Create(tab interface{}) bool

创建记录

func CreateTable

func CreateTable(tab interface{})

创建表格,如果表格不存在

func Find

func Find(out interface{}, tableName string, where ...interface{})

查询所有记录,参数一为结构体数组指针,参数二为表名,后面参数是查询套件

func First

func First(tab interface{}, where ...interface{}) bool

查询符合条件的第一条记录,有数据返回true,无数据返回false

func GetTableName

func GetTableName(value interface{}) (tableName string)

解析获得用户要操作的表名

func InitChannelList

func InitChannelList()

初始化创建通道列表-ChannelList

func InitDB

func InitDB()

func InitDeviceList

func InitDeviceList()

初始化创建设备信息表-DeviceList

func Limit

func Limit(out interface{}, tableName string, limit, offset int, where ...interface{})

分页查询

func Save

func Save(tab interface{}) bool

添加记录到表格中,存在则更新,不存在则插入

func UpdateTable

func UpdateTable(sql string)

更新数据库中表格的状态

func Updates

func Updates(tbl interface{}, data interface{})

执行更新操作,更新更改字段

Types

type ChannelList

type ChannelList struct {
	ID          int
	ChannelID   string            `gorm:"column:ChannelID;primary_key" json:"channelID"` //ChannelID=DeviceID_Number
	ChannelName string            `gorm:"column:ChannelName" json:"channelName"`
	DeviceID    string            `gorm:"column:DeviceID" json:"deviceID"`
	Status      string            `gorm:"column:Status" json:"status"` //通道在线状态,ON-在线,OFF-离线
	CreatedAt   config.TimeNormal `gorm:"column:CreatedAt" json:"createdAt"`
	UpdatedAt   config.TimeNormal `gorm:"column:UpdatedAt" json:"updatedAt"`
}

通道列表

func (ChannelList) TableName

func (ChannelList) TableName() string

设置表名

type DeviceList

type DeviceList struct {
	ID           int
	DeviceID     string            `gorm:"column:DeviceID;primary_key" json:"deviceID"` //设备ID
	DeviceIP     string            `gorm:"column:DeviceIP" json:"deviceIP"`             //来自设备注册时的UDPAddr
	DeviceName   string            `gorm:"column:DeviceName" json:"deviceName"`
	SerialNumber string            `gorm:"column:SerialNumber" json:"serialNumber"` //设备序列号
	Status       string            `gorm:"column:Status" json:"status"`             //设备在线状态,ON-在线,OFF-离线
	CreatedAt    config.TimeNormal `gorm:"column:CreatedAt" json:"createdAt"`
	UpdatedAt    config.TimeNormal `gorm:"column:UpdatedAt" json:"updatedAt"`
}

设备列表

func (DeviceList) TableName

func (DeviceList) TableName() string

设置表名

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL