dbutils

package
v0.0.0-...-212a885 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

* @Author: Wangjun * @Date: 2021-05-15 22:43:19 * @LastEditTime: 2022-04-11 09:22:49 * @LastEditors: Wangjun * @Description: * @FilePath: \golib\dbutils\dbutils.go * hnxr

Index

Constants

View Source
const SysAppConfFlag = "app_system_config"

SysAppConfFlag 系统标志

Variables

This section is empty.

Functions

func ClearTable

func ClearTable(parent string) error

ClearTable 清空表

func Count

func Count(parent string) (n int64, err error)

Count 统计记录数

func Map

func Map(parent string) (m map[string]string, err error)

Map ...

func ParseBool

func ParseBool(val interface{}) (value bool, err error)

ParseBool 格式化布尔类型

func Save

func Save(db *gorm.DB, record interface{}) (err error)

Save 保存数据, 有则更新,无则插入

func SetDatabase

func SetDatabase(db *gorm.DB, confs ...*AppConf)

SetDatabase 设置配置数据库

func Sync

func Sync(table []*AppConf, parent string) (err error)

Sync 同步到数据库

Types

type AppConf

type AppConf struct {
	UpdatedAt Time
	ID        uint     `gorm:"primary_key"`
	Parent    string   `gorm:"type:varchar(255)"`
	Scope     string   `gorm:"type:varchar(255)"`           //测点类型, 是否是高级
	Name      string   `gorm:"type:varchar(255)"`           //页面显示的数据
	Key       string   `gorm:"type:varchar(255)"`           //显示数据对应的KEY
	Value     string   `gorm:"type:varchar(255)"`           //需要配置的值
	Desc      string   `gorm:"type:varchar(255);column:ed"` //描述信息
	Type      string   `gorm:"type:varchar(255)"`           //填充模式
	Data      string   `gorm:"type:varchar(255)"`           //字段候选值
	Rows      []string `gorm:"-"`                           //字段候选值,供前台使用
}

AppConf 定义配置表结构

func AddDefaultSerial

func AddDefaultSerial() []*AppConf

AddDefaultSerial 添加默认的串口配置

func AddRow

func AddRow(name, key, value, desc, scope, typ, data string) *AppConf

AddRow 新加一行 name 显示名称 key 关键字 value 值 desc 描述 scope 作用域 type 类型 data 类型值

func Find

func Find(parent string) (rows []*AppConf, err error)

Find 查找满足指定条件的数据

func MakeDetails

func MakeDetails(parent string, prefix ...string) (rows []*AppConf, err error)

MakeDetails 生成行

func (*AppConf) Delete

func (a *AppConf) Delete(db *gorm.DB) error

Delete 删除

func (*AppConf) DeleteByParent

func (a *AppConf) DeleteByParent(db *gorm.DB, parent string) error

DeleteByParent 删除指定的数据

func (*AppConf) Insert

func (a *AppConf) Insert(db *gorm.DB) error

Insert 新建

func (*AppConf) Update

func (a *AppConf) Update(db *gorm.DB) error

Update 更新

type Conf

type Conf struct {
	Lock *sync.RWMutex
	// contains filtered or unexported fields
}

Conf 读取配置文件

func NewConf

func NewConf() *Conf

func NewFromMap

func NewFromMap(m map[string]string) *Conf

func (*Conf) Bool

func (conf *Conf) Bool(key string) (bool, error)

Bool Get bool value by key

func (*Conf) DIY

func (conf *Conf) DIY(key string) (interface{}, error)

DIY Not implementation TODO 暂没实现

func (*Conf) DefaultBool

func (conf *Conf) DefaultBool(key string, defaultVal bool) bool

DefaultBool int64 value by key, if value is not exist, return defaultValue

func (*Conf) DefaultFloat

func (conf *Conf) DefaultFloat(key string, defaultVal float64) float64

DefaultFloat float64 value by key, if value is not exist, return defaultValue

func (*Conf) DefaultInt

func (conf *Conf) DefaultInt(key string, defaultVal int) int

DefaultInt Get int value by key, if value is not exist, return defaultValue

func (*Conf) DefaultInt64

func (conf *Conf) DefaultInt64(key string, defaultVal int64) int64

DefaultInt64 int64 value by key, if value is not exist, return defaultValue

func (*Conf) DefaultString

func (conf *Conf) DefaultString(key string, defaultVal string) string

DefaultString Get value by key, if value is not exist, return defaultValue

func (*Conf) DefaultStrings

func (conf *Conf) DefaultStrings(key string, defaultVal []string) []string

DefaultStrings Not implementation

func (*Conf) Float

func (conf *Conf) Float(key string) (float64, error)

Float Get float64 by key

func (*Conf) GetSection

func (conf *Conf) GetSection(section string) (map[string]string, error)

GetSection Not implementation

func (*Conf) Int

func (conf *Conf) Int(key string) (int, error)

Int Get int value by key

func (*Conf) Int64

func (conf *Conf) Int64(key string) (int64, error)

Int64 Get int64 value by key

func (*Conf) Parse

func (conf *Conf) Parse(key string) (c config.Configer, err error)

Parse 从关系库表中读取配置

func (*Conf) ParseData

func (conf *Conf) ParseData(data []byte) (config.Configer, error)

ParseData Not implementation

func (*Conf) SaveConfigFile

func (conf *Conf) SaveConfigFile(filename string) error

SaveConfigFile Save config

func (*Conf) Set

func (conf *Conf) Set(key, val string) (err error)

Set 重设指定的Key Value

func (*Conf) String

func (conf *Conf) String(key string) (s string)

String Get string value

func (*Conf) Strings

func (conf *Conf) Strings(key string) (ss []string)

Strings 没实现

type Time

type Time struct {
	time.Time
}

Time 时间自动格式化

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. The time is a quoted string in RFC 3339 format, with sub-second precision added if present.

func (*Time) String

func (t *Time) String() string

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. The time is expected to be a quoted string in RFC 3339 format.

Jump to

Keyboard shortcuts

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