CoreSQL2

package
v5.1.17 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//WaitLog 为减少和外部模块的侵入性,此设计将记录一些必要的元素内容,外部抽取后释放即可
	// 等待处理的请求记录
	WaitLog     []WaitLogType
	WaitLogLock sync.Mutex
)
View Source
var (

	//OpenDebug debug
	OpenDebug = false
)

Functions

This section is empty.

Types

type ArgsAddress

type ArgsAddress struct {
	//所属国家 国家代码
	// eg: china => 86
	Country int `db:"country" json:"country" check:"country" empty:"true"`
	//省份 编码
	// eg: 710000
	Province int `db:"province" json:"province"`
	//所属城市
	City int `db:"city" json:"city" check:"city" empty:"true"`
	//街道详细信息
	Address string `db:"address" json:"address"`
	//地图制式
	// 0 WGS-84 / 1 GCJ-02 / 2 BD-09
	MapType int `db:"map_type" json:"mapType"`
	//坐标位置
	Longitude float64 `db:"longitude" json:"longitude"`
	Latitude  float64 `db:"latitude" json:"latitude"`
	//联系人姓名
	Name string `db:"name" json:"name"`
	//联系人国家代码
	NationCode string `db:"nation_code" json:"nationCode"`
	//联系人手机号
	Phone string `db:"phone" json:"phone"`
}

func (*ArgsAddress) GetField

func (t *ArgsAddress) GetField() FieldsAddress

type ArgsConfig

type ArgsConfig struct {
	//标识码
	Mark string `db:"mark" json:"mark" check:"mark" empty:"true"`
	//值
	Val string `db:"val" json:"val"`
}

ArgsConfig 扩展结构

func (*ArgsConfig) GetField

func (t *ArgsConfig) GetField() FieldsConfig

type ArgsConfigList

type ArgsConfigList []ArgsConfig

func (ArgsConfigList) GetFields

func (t ArgsConfigList) GetFields() FieldsConfigList

type ArgsGPS

type ArgsGPS struct {
	//坐标位置
	Longitude float64 `db:"longitude" json:"longitude"`
	Latitude  float64 `db:"latitude" json:"latitude"`
}

func (ArgsGPS) GetFields

func (t ArgsGPS) GetFields() FieldsGPS

GetFields 获取SQL数据

type ArgsID

type ArgsID struct {
	//ID
	ID int64 `db:"id" json:"id" check:"id"`
}

type ArgsPages

type ArgsPages struct {
	Page int64  `json:"page" check:"page"`
	Max  int64  `json:"max" check:"max"`
	Sort string `json:"sort" check:"sort"`
	Desc bool   `json:"desc" check:"desc"`
}

ArgsPages 分页结构体

func (*ArgsPages) GetCacheMark

func (t *ArgsPages) GetCacheMark() string

GetCacheMark 获取缓冲名称

type ArgsTimeBetween

type ArgsTimeBetween struct {
	//最小时间
	// Default时间
	MinTime string `json:"minTime" check:"defaultTime"`
	//最大时间
	// Default时间
	MaxTime string `json:"maxTime" check:"defaultTime"`
}

func (*ArgsTimeBetween) GetFields

func (t *ArgsTimeBetween) GetFields() (FieldsTimeBetween, error)

type Client

type Client struct {
	//sql操作核心
	DB *SQLClient
	//表名称
	TableName string
	//关键索引
	Key string
	// contains filtered or unexported fields
}

Client 操作表核心 具体的表定义对象即可使用

func (*Client) Analysis

func (t *Client) Analysis() *ClientAnalysisCtx

func (*Client) Delete

func (t *Client) Delete() *ClientDeleteCtx

func (*Client) Get

func (t *Client) Get() *ClientGetCtx

func (*Client) GetKey

func (t *Client) GetKey() string

func (*Client) Init

func (t *Client) Init(mainDB *SQLClient, tableName string) *Client

func (*Client) Insert

func (t *Client) Insert() *ClientInsertCtx

func (*Client) Select

func (t *Client) Select() *ClientListCtx

func (*Client) SetCache

func (t *Client) SetCache(obj *CoreCache.CacheData) *Client

func (*Client) SetCreateLock

func (t *Client) SetCreateLock(b bool) *Client

func (*Client) SetDeleteLock

func (t *Client) SetDeleteLock(b bool) *Client

func (*Client) SetEditLock

func (t *Client) SetEditLock(b bool) *Client

func (*Client) SetExpireSec

func (t *Client) SetExpireSec(sec int) *Client

func (*Client) SetKey

func (t *Client) SetKey(key string) *Client

func (*Client) SetUpdateLock

func (t *Client) SetUpdateLock(b bool) *Client

func (*Client) SetViewLock

func (t *Client) SetViewLock(b bool) *Client

func (*Client) Update

func (t *Client) Update() *ClientUpdateCtx

type ClientAnalysisCountFieldCtx

type ClientAnalysisCountFieldCtx struct {
	//字段名
	Name string
	//聚合方法
	// sum 加; avg 平均
	Type string
}

type ClientAnalysisCtx

type ClientAnalysisCtx struct {
	// contains filtered or unexported fields
}

ClientAnalysisCtx 排名处理器

func (*ClientAnalysisCtx) AVG

func (t *ClientAnalysisCtx) AVG(where string, args ...any) (val float64)

func (*ClientAnalysisCtx) Count

func (t *ClientAnalysisCtx) Count(where string, args ...any) (val int64)

func (*ClientAnalysisCtx) DataNoDelete

func (t *ClientAnalysisCtx) DataNoDelete() *ClientAnalysisCtx

DataNoDelete SQL结构体不含删除标记

func (*ClientAnalysisCtx) Max

func (t *ClientAnalysisCtx) Max(where string, args ...any) (val int64)

func (*ClientAnalysisCtx) Min

func (t *ClientAnalysisCtx) Min(where string, args ...any) (val int64)

func (*ClientAnalysisCtx) Sum

func (t *ClientAnalysisCtx) Sum(data any, fields []string, where string, args ...any) (err error)

func (*ClientAnalysisCtx) Sum2

func (t *ClientAnalysisCtx) Sum2(where string, args ...any) (val int64)

type ClientCtx

type ClientCtx struct {
	// contains filtered or unexported fields
}

func (*ClientCtx) DataNoDelete

func (t *ClientCtx) DataNoDelete() *ClientCtx

func (*ClientCtx) Exec

func (t *ClientCtx) Exec(query string, args ...any) (sql.Result, error)

Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.

Exec uses context.Background internally; to specify the context, use ExecContext.

func (*ClientCtx) Get

func (t *ClientCtx) Get(dest interface{}, query string, args ...interface{}) error

Get using this DB. Any placeholder parameters are replaced with supplied args. An error is returned if the result set is empty.

func (*ClientCtx) GetFields

func (t *ClientCtx) GetFields(l []string) string

func (*ClientCtx) MustBegin

func (t *ClientCtx) MustBegin() *sqlx.Tx

MustBegin starts a transaction, and panics on error. Returns an *sqlx.Tx instead of an *sql.Tx.

func (*ClientCtx) NamedExec

func (t *ClientCtx) NamedExec(query string, arg interface{}) (sql.Result, error)

NamedExec using this DB. Any named placeholder parameters are replaced with fields from arg.

func (*ClientCtx) Ping

func (t *ClientCtx) Ping() error

Ping verifies a connection to the database is still alive, establishing a connection if necessary.

Ping uses context.Background internally; to specify the context, use PingContext.

func (*ClientCtx) PrepareNamed

func (t *ClientCtx) PrepareNamed(query string) (*sqlx.NamedStmt, error)

PrepareNamed returns an sqlx.NamedStmt

func (*ClientCtx) Select

func (t *ClientCtx) Select(dest interface{}, query string, args ...interface{}) error

Select using this DB. Any placeholder parameters are replaced with supplied args.

type ClientDeleteCtx

type ClientDeleteCtx struct {
	// contains filtered or unexported fields
}

func (*ClientDeleteCtx) AddWhereID

func (t *ClientDeleteCtx) AddWhereID(id int64) *ClientDeleteCtx

AddWhereID 添加ID条件

func (*ClientDeleteCtx) AddWhereOrgID

func (t *ClientDeleteCtx) AddWhereOrgID(orgID int64) *ClientDeleteCtx

AddWhereOrgID 添加组织ID条件

func (*ClientDeleteCtx) AddWhereUserID

func (t *ClientDeleteCtx) AddWhereUserID(userID int64) *ClientDeleteCtx

AddWhereUserID 添加用户ID条件

func (*ClientDeleteCtx) Exec

func (t *ClientDeleteCtx) Exec(where string, args ...any) error

Exec 执行删除

func (*ClientDeleteCtx) ExecAny

func (t *ClientDeleteCtx) ExecAny(arg interface{}) error

ExecAny 执行删除

func (*ClientDeleteCtx) ExecNamed

func (t *ClientDeleteCtx) ExecNamed(arg map[string]interface{}) error

ExecNamed 执行删除 需要给与map[string]interface{}的参数 如果没有,则可以给与nil,程序会自动跳过

func (*ClientDeleteCtx) NeedSoft

func (t *ClientDeleteCtx) NeedSoft(b bool) *ClientDeleteCtx

NeedSoft 是否软删除

func (*ClientDeleteCtx) SetWhereAnd

func (t *ClientDeleteCtx) SetWhereAnd(name string, val interface{}) *ClientDeleteCtx

SetWhereAnd 添加等于关系判断

func (*ClientDeleteCtx) SetWhereOrThan

func (t *ClientDeleteCtx) SetWhereOrThan(name string, val interface{}) *ClientDeleteCtx

SetWhereOrThan 设置条件或查询关系 可用于负数跳过、0以上等于的判断机制

func (*ClientDeleteCtx) SetWhereStr

func (t *ClientDeleteCtx) SetWhereStr(where string, arg map[string]interface{}) *ClientDeleteCtx

SetWhereStr 追加覆盖条件部分

type ClientGetCtx

type ClientGetCtx struct {
	// contains filtered or unexported fields
}

func (*ClientGetCtx) AppendWhere

func (t *ClientGetCtx) AppendWhere(where string, args ...interface{}) *ClientGetCtx

func (*ClientGetCtx) GetByCodeAndOrgID

func (t *ClientGetCtx) GetByCodeAndOrgID(code string, orgID int64) *ClientGetCtx

func (*ClientGetCtx) GetByID

func (t *ClientGetCtx) GetByID(id int64) *ClientGetCtx

func (*ClientGetCtx) GetByIDAndOrgID

func (t *ClientGetCtx) GetByIDAndOrgID(id int64, orgID int64) *ClientGetCtx

func (*ClientGetCtx) GetByIDAndUserID

func (t *ClientGetCtx) GetByIDAndUserID(id int64, userID int64) *ClientGetCtx

func (*ClientGetCtx) GetByMarkAndOrgID

func (t *ClientGetCtx) GetByMarkAndOrgID(mark string, orgID int64) *ClientGetCtx

func (*ClientGetCtx) NeedLimit

func (t *ClientGetCtx) NeedLimit() *ClientGetCtx

NeedLimit 限制避免条件过于宽松,造成获取多条数据的异常问题

func (*ClientGetCtx) NeedSort

func (t *ClientGetCtx) NeedSort(needSort bool, sortField string, sortIsDesc bool) *ClientGetCtx

NeedSort 启动排序,用于反馈仅有数据时,获得最新或最早一条数据的设计

func (*ClientGetCtx) Result

func (t *ClientGetCtx) Result(data interface{}) error

func (*ClientGetCtx) SetFieldsOne

func (t *ClientGetCtx) SetFieldsOne(fields []string) *ClientGetCtx

type ClientInsertCtx

type ClientInsertCtx struct {
	// contains filtered or unexported fields
}

func (*ClientInsertCtx) Add

func (t *ClientInsertCtx) Add(args interface{}) *ClientInsertCtx

func (*ClientInsertCtx) Exec

func (t *ClientInsertCtx) Exec() error

Exec 执行 TODO: 核对代码存在问题,参数没有正确写入

func (*ClientInsertCtx) ExecAndCheckID

func (t *ClientInsertCtx) ExecAndCheckID() error

func (*ClientInsertCtx) ExecAndResultData

func (t *ClientInsertCtx) ExecAndResultData(data interface{}) error

ExecAndResultData 执行并返回数据 TODO: 部分场景下正常写入,但反馈失败信息

func (*ClientInsertCtx) ExecAndResultID

func (t *ClientInsertCtx) ExecAndResultID() (int64, error)

func (*ClientInsertCtx) SetFields

func (t *ClientInsertCtx) SetFields(fields []string) *ClientInsertCtx

type ClientListCtx

type ClientListCtx struct {
	// contains filtered or unexported fields
}

func (*ClientListCtx) Result

func (t *ClientListCtx) Result(data interface{}) error

func (*ClientListCtx) ResultAndCount

func (t *ClientListCtx) ResultAndCount(data interface{}) (count int64, err error)

func (*ClientListCtx) ResultCount added in v5.1.2

func (t *ClientListCtx) ResultCount() (count int64, err error)

func (*ClientListCtx) SelectList

func (t *ClientListCtx) SelectList(where string, args ...interface{}) *ClientListCtx

SelectList 如果启用了自动组合方法,请尽可能不要使用本方法where和args,否则请在where条件中明确一共注入了几个参数,并从对应参数为起点计算,避免$x顺序不匹配

func (*ClientListCtx) SetDeleteQuery

func (t *ClientListCtx) SetDeleteQuery(field string, param bool) *ClientListCtx

SetDeleteQuery 设置删除查询 如果启动此设定,请注意基于查询条件的$顺序,叠加后使用,否则讲造成条件和参数不匹配

func (*ClientListCtx) SetFieldsList

func (t *ClientListCtx) SetFieldsList(fields []string) *ClientListCtx

func (*ClientListCtx) SetFieldsSort

func (t *ClientListCtx) SetFieldsSort(fields []string) *ClientListCtx

func (*ClientListCtx) SetIDQuery

func (t *ClientListCtx) SetIDQuery(field string, param int64) *ClientListCtx

SetIDQuery 常规ID判断查询

func (*ClientListCtx) SetIDsQuery added in v5.1.5

func (t *ClientListCtx) SetIDsQuery(field string, param pq.Int64Array) *ClientListCtx

SetIDsQuery 常规IDs判断查询

func (*ClientListCtx) SetIntQuery added in v5.1.5

func (t *ClientListCtx) SetIntQuery(field string, param int) *ClientListCtx

SetIntQuery 常规Int判断查询

func (*ClientListCtx) SetPages

func (t *ClientListCtx) SetPages(pages ArgsPages) *ClientListCtx

func (*ClientListCtx) SetSearchQuery

func (t *ClientListCtx) SetSearchQuery(fields []string, search string) *ClientListCtx

SetSearchQuery 设置搜索查询 如果启动此设定,请注意基于查询条件的$顺序,叠加后使用,否则讲造成条件和参数不匹配

func (*ClientListCtx) SetStringQuery

func (t *ClientListCtx) SetStringQuery(field string, param string) *ClientListCtx

SetStringQuery 常规字符串判断查询

func (*ClientListCtx) SetTimeBetweenQuery added in v5.1.8

func (t *ClientListCtx) SetTimeBetweenQuery(field string, startAt time.Time, endAt time.Time) *ClientListCtx

SetTimeBetweenQuery 设置时间范围

type ClientUpdateCtx

type ClientUpdateCtx struct {
	// contains filtered or unexported fields
}

func (*ClientUpdateCtx) AddWhereID

func (t *ClientUpdateCtx) AddWhereID(id int64) *ClientUpdateCtx

func (*ClientUpdateCtx) AddWhereOrgID

func (t *ClientUpdateCtx) AddWhereOrgID(orgID int64) *ClientUpdateCtx

func (*ClientUpdateCtx) AddWhereUserID

func (t *ClientUpdateCtx) AddWhereUserID(userID int64) *ClientUpdateCtx

func (*ClientUpdateCtx) NamedExec

func (t *ClientUpdateCtx) NamedExec(arg map[string]interface{}) error

func (*ClientUpdateCtx) NeedSoft

func (t *ClientUpdateCtx) NeedSoft(b bool) *ClientUpdateCtx

NeedSoft 是否软删除

func (*ClientUpdateCtx) NeedUpdateTime

func (t *ClientUpdateCtx) NeedUpdateTime() *ClientUpdateCtx

func (*ClientUpdateCtx) SetFieldStr

func (t *ClientUpdateCtx) SetFieldStr(fields string) *ClientUpdateCtx

func (*ClientUpdateCtx) SetFields

func (t *ClientUpdateCtx) SetFields(fields []string) *ClientUpdateCtx

func (*ClientUpdateCtx) SetWhereAnd

func (t *ClientUpdateCtx) SetWhereAnd(name string, val interface{}) *ClientUpdateCtx

func (*ClientUpdateCtx) SetWhereOrThan

func (t *ClientUpdateCtx) SetWhereOrThan(name string, val interface{}) *ClientUpdateCtx

func (*ClientUpdateCtx) SetWhereStr

func (t *ClientUpdateCtx) SetWhereStr(where string, arg map[string]interface{}) *ClientUpdateCtx

SetWhereStr 追加覆盖条件部分

type FieldsAddress

type FieldsAddress struct {
	//所属国家 国家代码
	// eg: china => 86
	Country int `db:"country" json:"country"`
	//省份 编码
	// eg: 710000
	Province int `db:"province" json:"province"`
	//所属城市
	City int `db:"city" json:"city" check:"city"`
	//街道详细信息
	Address string `db:"address" json:"address"`
	//地图制式
	// 0 WGS-84 / 1 GCJ-02 / 2 BD-09
	MapType int `db:"map_type" json:"mapType"`
	//坐标位置
	Longitude float64 `db:"longitude" json:"longitude"`
	Latitude  float64 `db:"latitude" json:"latitude"`
	//联系人姓名
	Name string `db:"name" json:"name"`
	//联系人国家代码
	NationCode string `db:"nation_code" json:"nationCode"`
	//联系人手机号
	Phone string `db:"phone" json:"phone"`
}

FieldsAddress 通用地址结构

func (*FieldsAddress) Check

func (t *FieldsAddress) Check() (err error)

func (*FieldsAddress) GetMapType

func (t *FieldsAddress) GetMapType() (data string)

func (*FieldsAddress) Scan

func (t *FieldsAddress) Scan(value interface{}) error

func (FieldsAddress) Value

func (t FieldsAddress) Value() (driver.Value, error)

Value sql底层处理器

type FieldsConfig

type FieldsConfig struct {
	//标识码
	Mark string `db:"mark" json:"mark"`
	//值
	Val string `db:"val" json:"val"`
}

FieldsConfig 扩展结构

func (*FieldsConfig) Scan

func (t *FieldsConfig) Scan(value interface{}) error

func (FieldsConfig) Value

func (t FieldsConfig) Value() (driver.Value, error)

Value sql底层处理器

type FieldsConfigList

type FieldsConfigList []FieldsConfig

FieldsConfigList 简化得扩展结构

func Set

func Set(data FieldsConfigList, mark string, val interface{}) FieldsConfigList

Set 写入数据

func (FieldsConfigList) CheckVal

func (t FieldsConfigList) CheckVal(mark string, val string) (nowVal string, b bool)

CheckVal 检查一组数据内的值是否匹配

func (FieldsConfigList) GetVal

func (t FieldsConfigList) GetVal(mark string) (val string, b bool)

GetVal 抽取指定的值

func (FieldsConfigList) GetValBool

func (t FieldsConfigList) GetValBool(mark string) (val bool, b bool)

GetValBool 抽取指定的值

func (FieldsConfigList) GetValFloat64

func (t FieldsConfigList) GetValFloat64(mark string) (val float64, b bool)

GetValFloat64 抽取指定的值

func (FieldsConfigList) GetValInt

func (t FieldsConfigList) GetValInt(mark string) (val int, b bool)

GetValInt 抽取指定的值

func (FieldsConfigList) GetValInt64

func (t FieldsConfigList) GetValInt64(mark string) (val int64, b bool)

GetValInt64 抽取指定的值

func (FieldsConfigList) GetValInt64NoBool

func (t FieldsConfigList) GetValInt64NoBool(mark string) (val int64)

func (FieldsConfigList) GetValNoBool

func (t FieldsConfigList) GetValNoBool(mark string) (val string)

func (FieldsConfigList) GetValNoErr

func (t FieldsConfigList) GetValNoErr(mark string) (val string)

func (*FieldsConfigList) Scan

func (t *FieldsConfigList) Scan(value interface{}) error

func (FieldsConfigList) Value

func (t FieldsConfigList) Value() (driver.Value, error)

Value sql底层处理器

type FieldsGPS

type FieldsGPS struct {
	//坐标位置
	Longitude float64 `db:"longitude" json:"longitude"`
	Latitude  float64 `db:"latitude" json:"latitude"`
}

FieldsGPS 坐标设计

func (*FieldsGPS) Scan

func (t *FieldsGPS) Scan(value interface{}) error

func (FieldsGPS) Value

func (t FieldsGPS) Value() (driver.Value, error)

Value sql底层处理器

type FieldsTimeBetween

type FieldsTimeBetween struct {
	//最小时间
	MinTime time.Time `json:"minTime"`
	//最大时间
	MaxTime time.Time `json:"maxTime"`
}

func (*FieldsTimeBetween) GetData

func (t *FieldsTimeBetween) GetData() ArgsTimeBetween

type SQLClient

type SQLClient struct {
	// contains filtered or unexported fields
}

SQLClient SQL操作控制器核心 初始化连接后需使用本结构构建控制对象,写入基础数据集

func (*SQLClient) GetPostgresql

func (t *SQLClient) GetPostgresql() *CorePostgres.Client

GetPostgresql 获取postgresql句柄

func (*SQLClient) InitMssql

func (t *SQLClient) InitMssql(mainDB *CoreMsSQL.Client)

InitMssql 初始化

func (*SQLClient) InitPostgresql

func (t *SQLClient) InitPostgresql(mainDB *CorePostgres.Client)

InitPostgresql 初始化

func (*SQLClient) InitSQLDB

func (t *SQLClient) InitSQLDB(mode string, mainDB *sqlx.DB)

InitSQLDB 初始化

type WaitLogType

type WaitLogType struct {
	//动作类型
	// select/get/insert/update/delete/analysis
	Action string
	//消息内容
	Msg string
	//是否为事务关系
	IsBegin bool
	//开始时间
	StartAt time.Time
	//结束时间
	EndAt time.Time
	//执行时间
	RunSec int64
	//反馈尺寸 单位字节
	ResultSize int64
	//是否存在报错
	Err error
}

Jump to

Keyboard shortcuts

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