dbinfo

package module
v0.0.0-...-63715d1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2025 License: GPL-3.0 Imports: 14 Imported by: 8

Documentation

Index

Constants

View Source
const (
	Eq         = "="
	Lt         = "<"
	Le         = "<="
	Gt         = ">"
	Ge         = ">="
	Ne         = "<>"
	Between    = "BETWEEN"
	NotBetween = "NOT BETWEEN"
	Like       = "LIKE"
	NoLike     = "NOT LIKE"
	IsNull     = "IS NULL"
	IsNotNull  = "IS NOT NULL"
	In         = "IN"
	NotIn      = "NOT IN"
)

*

  • @Description: 查询条件符号
View Source
const SPECIAL_STR = "/INTEGER/STRING/INT/NULL/LONG/FLOAT/DOUBLE/FUNCTION/" // /Integer/string/int/null/long/float/double/function/

要被过滤的特殊字符串,用'/'分隔

Variables

View Source
var (
	BaseSystemName           string //基本数据库库名
	TableMajorKeyString      string //数据库表主键名称(字符串形式)
	TableMajorKeyAutoInt     string //数据库表主键名称(自增长形式)
	TableMajorKeyUuId        string //数据库表主键名称(UUID形式)
	TablePidKey              string //数据库表字段名称-上级字段名
	TablePathKey             string //数据库表字段名称-主键路径名
	TableTreeNodeName        string //数据库表字段名称-树形节点名
	TableCreatorName         string //数据库表字段名称-创建人
	TableCreateDateName      string //数据库表字段名称-创建时间
	TableModifiederName      string //数据库表字段名称-修改人
	TableModifiedDateName    string //数据库表字段名称-修改时间
	TableStateName           string //数据库表字段名称-状态值
	TableIndexName           string //数据库表字段名称-排序值
	TableVersionName         string //数据库表字段名称-版本号
	TablePasswordName        string //数据库表字段名称-密码
	TableDelSignName         string //数据库表字段名称-逻辑删除标识
	TableSetpName            string //数据库表字段名称-步骤值
	TableOnlyignName         string //数据库表字段名称-唯一标识
	TableNameDictionary      string //字典表表名
	TableDictionaryValueName string //字典表值字段名
	TableRecordKeyName       string //记录验证串字段名
	TablesSign               string //标识字段名
	TablesMemo               string //备注字段名

	TableTreeRootValue = "00" //数据库树型表根节点默认值
)

Functions

func BaseColumnNameList

func BaseColumnNameList(entity Entity) []string

*

  • 结构体映射表的字段名集合
  • @param entity
  • @return

func CheckRecordKey

func CheckRecordKey(entity Entity) bool

*

  • 验证'记录验证串'是否正确
  • @param entity
  • @return

func CreateRecordKey

func CreateRecordKey(entity Entity) string

* 创建记录验证值 * @param entity * @return

func CreateRecordKeyByMap

func CreateRecordKeyByMap(entity Entity, data map[string]interface{}) string

* 根据结构体创建map的记录验证值 * @param entity 参照结构体,仅用于取结构 * @param data 数据 * @return

func EntityAutoKey

func EntityAutoKey(entity Entity) bool

func EntityDbName

func EntityDbName(entity Entity) string

*

  • 取所属数据库名
  • @param entity
  • @return

func EntityHasCreateDate

func EntityHasCreateDate(entity Entity) bool

func EntityHasCreator

func EntityHasCreator(entity Entity) bool

func EntityHasDelSign

func EntityHasDelSign(entity Entity) bool

func EntityHasIndex

func EntityHasIndex(entity Entity) bool

func EntityHasMemo

func EntityHasMemo(entity Entity) bool

func EntityHasModifiedDate

func EntityHasModifiedDate(entity Entity) bool

func EntityHasModifieder

func EntityHasModifieder(entity Entity) bool

func EntityHasOnlyign

func EntityHasOnlyign(entity Entity) bool

func EntityHasPassword

func EntityHasPassword(entity Entity) bool

func EntityHasPath

func EntityHasPath(entity Entity) bool

func EntityHasPid

func EntityHasPid(entity Entity) bool

func EntityHasRecordKey

func EntityHasRecordKey(entity Entity) bool

func EntityHasSign

func EntityHasSign(entity Entity) bool

func EntityHasState

func EntityHasState(entity Entity) bool

func EntityHasVersion

func EntityHasVersion(entity Entity) bool

func EntityKeyLength

func EntityKeyLength(entity Entity) int

*

  • 取所属数据库表主键长度
  • 注意:如果有多个主键,则取第一个主键
  • @param entity
  • @return

func EntityKeyName

func EntityKeyName(entity Entity) string

*

  • 取所属数据库表主键名
  • 注意:如果有多个主键,则取第一个主键
  • @param entity
  • @return

func EntityKeyNames

func EntityKeyNames(entity Entity) string

*

  • 取所属数据库表主键名
  • 注意:如果有多个主键,则全取,并以','分隔
  • @param entity
  • @return

func EntityKeysLength

func EntityKeysLength(entity Entity) map[string]int

*

  • 取所属数据库表主键长度
  • 注意:如果有多个主键,则全取
  • @param entity
  • @return

func EntityTableName

func EntityTableName(entity Entity) string

*

  • 取所属数据库表名
  • @param entity
  • @return

func GetVal

func GetVal(entity Entity, name string) interface{}

*

  • 取数据值
  • @param entity
  • @param name 字段名
  • @return

func HasColumnName

func HasColumnName(entity Entity, name string) bool

*

  • 判断是否存在字段名
  • @param entity
  • @param name
  • @return

func HoldByEntity

func HoldByEntity(entity Entity, data map[string]interface{}) map[string]interface{}

*

  • 按实体保留map中的数据
  • object 待检查对象
  • data 数据
  • fieldPrefix 字段前缀(可不传)

func SetDefault

func SetDefault(entity Entity, cover bool)

*

  • 设置默认值
  • @param entity
  • @param cover 是否覆盖

func SetRecordKey

func SetRecordKey(entity Entity) string

*

  • 设置当前实体的'记录验证串'值
  • @param entity
  • @return 返回新值

func SetVal

func SetVal(entity Entity, name string, val interface{})

*

  • 设置数据值(此函数用于未知结构体的情况下调用)
  • @param name 字段名
  • @param val 值
  • @return

func SimpleTableName

func SimpleTableName(entity Entity) string

* 结构体简略表名(无库名) * @return

func ToMap

func ToMap(entity interface{}) map[string]interface{}

将结构体的所有属性及其值存入 map[string]interface{}

func TrimFields

func TrimFields(entity Entity)

*

  • 去除字符类型属性前后空格

func ValidAttr

func ValidAttr(data map[string]interface{}, entity Entity, ignoreNames []string) (int, error)

*

  • 对对象中添加了DataInfo注解的不为null的属性检查限制
  • data 数据
  • entity 检查用数据结构
  • ignoreNames 待忽略的字段

func ValidAttrByAdd

func ValidAttrByAdd(entity Entity, ignoreNames []string) (int, error)

*

  • 对'新增'对象中添加了DataInfo注解的属性检查限制
  • entity 检查用数据结构
  • ignoreNames 待忽略的字段

func ValidAttrByEdit

func ValidAttrByEdit(data map[string]interface{}, entity Entity, ignoreNames []string) (int, error)

*

  • 对'编辑'对象中添加了DataInfo注解的不为null的属性检查限制
  • data 数据
  • entity 检查用数据结构
  • ignoreNames 待忽略的字段

Types

type DataInfo

type DataInfo struct {
	GbDbField        bool        `json:"bDbField"`        //是否数据库字段
	GsName           string      `json:"sName"`           //名称
	GsDbName         string      `json:"sDbName"`         //所在数据库名称
	GsTableName      string      `json:"sTableName"`      //所在数据库表表名称
	GsKeyName        string      `json:"sKeyName"`        //表主键名称
	GiIndex          int         `json:"iIndex"`          //序号
	GiMaxLength      int         `json:"iMaxLength"`      //最大长度
	GbNull           bool        `json:"bNull"`           //是否允许为空
	Gbkey            bool        `json:"bkey"`            //是否主键
	GbExtra          bool        `json:"bExtra"`          //是否自增
	GbBigTxt         bool        `json:"bBigTxt"`         //是否大文本字段
	GsDefaultData    string      `json:"sDefaultData"`    //默认值
	GoDefaultData    interface{} `json:"oDefaultData"`    //默认值
	GsComment        string      `json:"sComment"`        //字段备注
	GbDecimal        bool        `json:"bDecimal"`        //类型是否有小数
	GiIntegralLength int         `json:"iIntegralLength"` //整数位的长度
	GiDecimalLength  int         `json:"iDecimalLength"`  //小数位的长度
	GsDbFileType     string      `json:"sDbFileType"`     //字段在数据库中的类型
	GsRelTitle       string      `json:"sRelTitle"`       //关联后显示的名称
	GsRelName        string      `json:"sRelName"`        //关联关系中被动关联的字段名,如 (LEFT JOIN RelTable ON RelTable.A = MainTable.B )中的A
	GsRelMainName    string      `json:"sRelMainName"`    //关联关系中被关联的字段名,如 (LEFT JOIN RelTable ON RelTable.A = MainTable.B )中的B
}

数据信息注解

func AllDataInfo

func AllDataInfo(entity Entity) []*DataInfo

*

  • 取所有数据结构信息
  • @param entity
  • @return

func GetDataInfo

func GetDataInfo(entity Entity, name string) *DataInfo

*

  • 按名称取数据结构信息
  • @param entity
  • @param name
  • @return

func GetDataInfoByIndex

func GetDataInfoByIndex(entity Entity, index int) *DataInfo

*

  • 按字段顺序取数据结构信息
  • @param entity
  • @param name
  • @return

func GetKeyDataInfo

func GetKeyDataInfo(entity Entity) []*DataInfo

*

  • 取主键数据结构信息
  • @param entity
  • @return

func (DataInfo) New

func (DataInfo) New() *DataInfo

创建结构体,并设置默认值

type Entity

type Entity interface {
	New() Entity                       //创建结构实体
	BaseColumnNames() string           //结构体映射表的字段名串
	BaseEntity() Entity                //取基础实体,用于在子类(嵌套结构体)时同样获得基类
	GetDataInfo(name string) *DataInfo //取数据结构信息
	TableName() string                 //结构体映射表名,当gorm进行查询时要明确与gorm规则不同的表名时使用
	OwnerName() string                 //结构体映射库名,去除'Dev_'等前缀
	OwnerTable() string                //结构体映射表名,无库名
}

实体接口定义,用于规范实体结构体

func BaseEntity

func BaseEntity(entity Entity) Entity

*

  • 取基础实体,用于在子类(嵌套结构体)时同样获得基类
  • @param entity
  • @return

func GetEntity

func GetEntity(name string) Entity

*

  • 取实体结构体
  • @param name
  • @return

func MapSetEntity

func MapSetEntity(data map[string]interface{}, entity Entity) Entity

Map设置结构体

func MapToEntity

func MapToEntity(data map[string]interface{}, entity Entity) Entity

将map数据转换为实体

func NewList

func NewList(entity Entity, iSize int) []Entity

*

  • 创建指定长度的结构实体集合
  • @param entity
  • @param iSize
  • @return

func RegisterEntity

func RegisterEntity(name string, entity Entity) Entity

*

  • 注册实体结构体
  • @param name
  • @param entity

func ToEntity

func ToEntity(data map[string]interface{}, entity Entity) (Entity, int, error)

*

  • 将map转成实体
  • data 数据
  • entity 数据结构

type FindByPageParam

type FindByPageParam struct {
	Gpage         Page        `json:"page"`         //分页信息对象
	Gorders       []OrderInfo `json:"orders"`       //排序信息对象集合
	GsLikeStr     string      `json:"sLikeStr"`     //全文检索条件
	GsLikeDateSt  string      `json:"sLikeDateSt"`  //全文检索查询记录修改时间范围条件-开始
	GsLikeDateEd  string      `json:"sLikeDateEd"`  //全文检索查询记录修改时间范围条件-结束
	Gcondition    interface{} `json:"condition"`    //常规查询条件对象(根据定义的类型转换)
	GsHideBigText bool        `json:"sHideBigText"` //是否隐藏大文本字段
	GsHideFields  string      `json:"sHideFields"`  //隐藏字段集合';'分隔
}

分页查询条件组合类

type OrderInfo

type OrderInfo struct {
	GsOrderDbName string `json:"sOrderDbName"` //排序字段名所属库名
	GsOrderTable  string `json:"sOrderTable"`  //排序字段名所属表
	GsOrderField  string `json:"sOrderField"`  //排序字段名
	GsDirection   string `json:"sDirection"`   //排序方式(升序ASC 降序DESC)
	GiIndex       int    `json:"iIndex"`       //排序顺序
}

排序信息

func (*OrderInfo) SetsDirection

func (o *OrderInfo) SetsDirection(sDirection string)

*

  • 设置 排序方式(升序ASC 降序DESC)
  • @param sDirection 排序方式(升序ASC 降序DESC)

func (*OrderInfo) SetsOrderDbName

func (o *OrderInfo) SetsOrderDbName(sOrderDbName string)

*

  • 设置 排序字段名所属库名
  • @param sOrderDbName 排序字段名所属库名

func (*OrderInfo) SetsOrderField

func (o *OrderInfo) SetsOrderField(sOrderField string)

*

  • 设置 排序字段名
  • @param sOrderField 排序字段名

func (*OrderInfo) SetsOrderTable

func (o *OrderInfo) SetsOrderTable(sOrderTable string)

*

  • 设置 排序字段名所属表
  • @param sOrderTable 排序字段名所属表

func (*OrderInfo) String

func (o *OrderInfo) String() string

*

  • 输出排序字符串

type Page

type Page struct {
	GiCurrent   int                      `json:"iCurrent"`   //当前页
	GiSize      int                      `json:"iSize"`      //每页显示记录
	GiCountRow  int                      `json:"iCountRow"`  //总记录数
	GiCountPage int                      `json:"iCountPage"` //总页数
	Record      []map[string]interface{} `json:"Record"`     //本页的数据列表
}

分页数据信息对象,常用于前端与后台列表数据交互

func (Page) New

func (Page) New() *Page

创建分页信息

func (*Page) Set

func (p *Page) Set(start, size, countRow int, record []map[string]interface{}) *Page

设置分页信息

func (*Page) SetRecord

func (p *Page) SetRecord(record []map[string]interface{}) *Page

设置数据列表

type TableInfo

type TableInfo struct {
	GsDbName          string `json:"sDbName"`          //所在数据库名称
	GsTableName       string `json:"sTableName"`       //所在数据库表表名称
	GsKeyName         string `json:"sKeyName"`         //表主键名称
	GiKeyLen          int    `json:"iKeyLen"`          //主键长度
	GbAutoKey         bool   `json:"bAutoKey"`         //是否自增主键
	GbHasPid          bool   `json:"bHasPid"`          //是否存在sPid
	GbHasPath         bool   `json:"bHasPath"`         //是否存在sPath
	GbHasRecordKey    bool   `json:"bHasRecordKey"`    //是否存在sRecordKey
	GbHasMemo         bool   `json:"bHasMemo"`         //是否存在sMemo
	GbHasCreator      bool   `json:"bHasCreator"`      //是否存在sCreator
	GbHasCreateDate   bool   `json:"bHasCreateDate"`   //是否存在dCreateDate
	GbHasModifieder   bool   `json:"bHasModifieder"`   //是否存在sModifieder
	GbHasModifiedDate bool   `json:"bHasModifiedDate"` //是否存在dModifiedDate
	GbHasState        bool   `json:"bHasState"`        //是否存在iState
	GbHasIndex        bool   `json:"bHasIndex"`        //是否存在iIndex
	GbHasVersion      bool   `json:"bHasVersion"`      //是否存在iVersion
	GbHasPassword     bool   `json:"bHasPassword"`     //是否存在sPassword
	GbHasSign         bool   `json:"bHasSign"`         //是否存在sSign
	GbHasOnlyign      bool   `json:"bHasOnlyign"`      //是否存在sOnlyign
	GbHasDelSign      bool   `json:"bHasDelSign"`      //是否存在iDelSign
	GsBigTextFields   string `json:"sBigTextFields"`   //大文本字段名称集合,';'分隔
}

数据信息注解

func GetTableInfo

func GetTableInfo(entity Entity) *TableInfo

*

  • 结构体映射表简化信息

type Time

type Time time.Time

自定义时间类型

func (*Time) MarshalJSON

func (tu *Time) MarshalJSON() ([]byte, error)

重写MarshalJSON方法来实现gorm查询时间字段事数据解析

func (Time) Now

func (tu Time) Now() Time

取当前时间

func (Time) String

func (tu Time) String() string

func (*Time) UnmarshalJSON

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

type WhereInfo

type WhereInfo struct {
	Name      string      //字段名
	Value     interface{} //字段值
	ValueName string      //值字段名,与Value互斥, 一般用于条件 Name < ValueNmae的情况,如 'where dStTime < dStopTime'
	Condition string      //查询条件符号
}

*

  • @Description: 查询条件

func NewWhereInfo

func NewWhereInfo(name string, value interface{}) *WhereInfo

Jump to

Keyboard shortcuts

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