sql

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	TypeInt = iota
	TypeInt8
	TypeInt16
	TypeInt32
	TypeInt64
	TypeUInt
	TypeUInt8
	TypeUInt16
	TypeUInt32
	TypeUInt64
	TypeFloat32
	TypeFloat64
	TypeString
	TypeTime
	TypeBytes
	TypeJSON
)

Variables

View Source
var ClickHouseTypeMap = map[string]int8{
	"Int":         TypeInt,
	"Int8":        TypeInt8,
	"Int16":       TypeInt16,
	"Int32":       TypeInt32,
	"Int64":       TypeInt64,
	"UInt":        TypeUInt,
	"UInt8":       TypeUInt8,
	"UInt16":      TypeUInt16,
	"UInt32":      TypeUInt32,
	"UInt64":      TypeUInt64,
	"Float":       TypeFloat32,
	"Float32":     TypeFloat32,
	"Float64":     TypeFloat64,
	"Decimal":     TypeFloat64,
	"String":      TypeString,
	"FixedString": TypeString,
	"UUID":        TypeString,
	"DateTime":    TypeTime,
	"DateTime64":  TypeTime,
	"Date":        TypeTime,
}
View Source
var MySQLTypeMap = map[string]int8{
	"INT":       TypeInt,
	"TINYINT":   TypeInt8,
	"SMALLINT":  TypeInt16,
	"MEDIUMINT": TypeInt32,
	"BIGINT":    TypeInt64,
	"BIT":       TypeBytes,
	"FLOAT":     TypeFloat32,
	"DOUBLE":    TypeFloat64,
	"DECIMAL":   TypeFloat64,
	"VARCHAR":   TypeString,
	"CHAR":      TypeString,
	"TEXT":      TypeString,
	"BLOB":      TypeBytes,
	"BINARY":    TypeBytes,
	"VARBINARY": TypeBytes,
	"TIME":      TypeString,
	"DATE":      TypeTime,
	"DATETIME":  TypeTime,
	"TIMESTAMP": TypeTime,
	"JSON":      TypeJSON,
}

Functions

func CountSQL

func CountSQL(statement *Statement) (sql string)

CountSQL 创建 count 语句

func DeleteSQL

func DeleteSQL(statement *Statement) string

DeleteSQL 创建 delete 语句

func FindSQL

func FindSQL(statement *Statement) (sql string)

FindSQL 组装mysql 语句

func GetSQLWithParams

func GetSQLWithParams(sql string, params []interface{}) string

func InsertSQL

func InsertSQL(statement *Statement) string

InsertSQL 创建 insert 语句

func ReplaceSQL

func ReplaceSQL(statement *Statement) string

ReplaceSQL 创建 replace 语句

func SetLocation

func SetLocation(l *time.Location)

SetLocation 慎重使用,此处影响的是全局的 NullTime 时间 logic 的时区

func UpdateSQL

func UpdateSQL(statement *Statement) string

UpdateSQL 创建 update 语句

Types

type Join

type Join struct {
	Type  string            `json:"type,omitempty"`
	Table string            `json:"table,omitempty"`
	Using []string          `json:"using,omitempty"`
	On    map[string]string `json:"on,omitempty"`
}

Join MySQL 表 JOIN

type NullBool

type NullBool struct {
	Bool   bool
	IsNull bool
}

NullBool 数据库 bool NULL 类型

func (*NullBool) Scan

func (ns *NullBool) Scan(value interface{}) error

Scan NullBool 类型实现 mysql 引擎查询赋值接口

type NullFloat

type NullFloat struct {
	Float  float64
	IsNull bool
}

NullFloat 数据库 double/float NULL 类型

func (*NullFloat) Scan

func (ns *NullFloat) Scan(value interface{}) error

Scan NullFloat 类型实现 mysql 引擎查询赋值接口

type NullInt

type NullInt struct {
	Int    int64
	IsNull bool
}

NullInt 数据库 int NULL 类型

func (*NullInt) Scan

func (ns *NullInt) Scan(value interface{}) error

Scan NullInt 类型实现 mysql 引擎查询赋值接口

type NullString

type NullString struct {
	String string
	IsNull bool
}

NullString 数据库 varchar NULL 类型

func (*NullString) Scan

func (ns *NullString) Scan(value interface{}) error

Scan NullString 类型实现 mysql 引擎查询赋值接口

type NullTime

type NullTime struct {
	Time       time.Time
	IsNull     bool
	TimeLayout string
}

NullTime 数据库 time NULL 类型

func (*NullTime) Scan

func (ns *NullTime) Scan(value interface{}) error

Scan NullTime 类型实现 mysql 引擎查询赋值接口,

type NullUint

type NullUint struct {
	Uint   uint64
	IsNull bool
}

NullUint 数据库 uint NULL 类型

func (*NullUint) Scan

func (ns *NullUint) Scan(value interface{}) error

Scan NullUint 类型实现 mysql 引擎查询赋值接口

type Query

type Query struct {
	OP            string
	Table, Alias  string
	Where, Having map[string]interface{}
	Column        []string
	Group         []string
	Order         []string
	Join          []*Join
	Data          map[string]interface{}
	Datas         []map[string]interface{}
	Page          int
	Size          int
	From          uint64
	SQL           string
	Params        []interface{}

	// 建表用
	Shard       []string
	IfNotExists bool

	DB        *obj.TblDB
	Addr      *util.DBAddress
	TblTable  *obj.TblTable
	TransInfo *obj.TransInfo
	TimeLog   *log.TimeLog
	// contains filtered or unexported fields
}

func (*Query) Count

func (q *Query) Count(ctx context.Context, s *Statement) (uint64, error)

Count 统计总数

func (*Query) Find

func (q *Query) Find(ctx context.Context, s *Statement,
	querySQL string, params []interface{}) (result map[string]interface{}, err error)

Find 查询符合要求的一条数据,返回结果为 map[string]string

func (*Query) FindAll

func (q *Query) FindAll(ctx context.Context, s *Statement,
	querySQL string, params []interface{}) (result []map[string]interface{}, err error)

FindAll 查询符合要求的所有数据,返回 []map[string]string 格式数据

func (*Query) InsertToCK

func (q *Query) InsertToCK(ctx context.Context, desc string, batch bool, retryTime int,
	table string, datas []map[string]interface{}) ([]map[string]interface{}, map[int]error, error)

InsertToCK clickhouse 批量插入,(必须通过事务生成批量语句,然后提交)

func (*Query) Query

func (q *Query) Query(ctx context.Context) (interface{}, *proto.Detail, bool, error)

Query sql 查询

func (*Query) SetParams

func (q *Query) SetParams(req *filter.Request,
	property *obj.Property, addr *util.DBAddress, transInfo *obj.TransInfo) error

func (*Query) Transaction

func (q *Query) Transaction(ctx context.Context, fn func(c *Query) error) error

Transaction 事务函数

type Statement

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

Statement 查询语句结构体

func (*Statement) GetOrder

func (s *Statement) GetOrder() string

GetOrder 获取排序 order

func (*Statement) GetParams

func (s *Statement) GetParams() []interface{}

GetParams 获取 params

func (*Statement) GetWhere

func (s *Statement) GetWhere() string

GetWhere 获取 where 条件

func (*Statement) Group

func (s *Statement) Group(group []string) *Statement

Group 分组 group by

func (*Statement) Having

func (s *Statement) Having(dbType int, having map[string]interface{}) *Statement

Having having语句

func (*Statement) Join

func (s *Statement) Join(joins []*Join) *Statement

Join 表 join

func (*Statement) Limit

func (s *Statement) Limit(limit int) *Statement

Limit 组装mysql limit 条件,可以使用分页配合使用

func (*Statement) Order

func (s *Statement) Order(orders []string) *Statement

Order 排序

func (*Statement) SetColumn

func (s *Statement) SetColumn(column []string) *Statement

SetColumn 设置列

func (*Statement) SetDBType

func (s *Statement) SetDBType(typ int) *Statement

SetDBType 设置库类型

func (*Statement) SetMaps

func (s *Statement) SetMaps(attributeArr []map[string]interface{}) *Statement

SetMaps insert、replace 数据

func (*Statement) SetTable

func (s *Statement) SetTable(table, alias string) *Statement

SetTable 设置表与别名

func (*Statement) UpdateMap

func (s *Statement) UpdateMap(attributes map[string]interface{}) *Statement

UpdateMap update 数据

func (*Statement) Where

func (s *Statement) Where(dbType int, where map[string]interface{}) *Statement

Where 快捷 where 查询条件组装

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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