Documentation ¶
Index ¶
- Constants
- Variables
- func GetFunctionHandlerSQL(function FunctionType, fp FunctionProvider) string
- func GetFunctionSQL(function FunctionType) string
- func IsConstantTypeSupported(constantType string) bool
- func IsDatabaseTypeSupported(dbType string) bool
- func IsFunctionTypeValid(function FunctionType) bool
- func PrintCallerInfo()
- func RegisterDatabase(dbType DBType, dataAccess DataAccess)
- func RegisterFunctionProvider(dbType DBType, dataAccess FunctionProvider)
- func RegisterOperator(dbType DBType, operator OperatorI)
- type ClickHouseDatabase
- type ClickhouseOperator
- func (co *ClickhouseOperator) Blank(condition Condition, qf *QueryFilter)
- func (co *ClickhouseOperator) BuildQuery(condition Condition, qf *QueryFilter)
- func (co *ClickhouseOperator) Equals(condition Condition, qf *QueryFilter)
- func (co *ClickhouseOperator) NotBlank(condition Condition, qf *QueryFilter)
- func (co *ClickhouseOperator) NotEqual(condition Condition, qf *QueryFilter)
- type Condition
- type ConditionBuilder
- func (cb *ConditionBuilder) AddCondition(condition Condition) *ConditionBuilder
- func (cb *ConditionBuilder) And() *ConditionBuilder
- func (cb *ConditionBuilder) Append(builder ConditionBuilder)
- func (cb *ConditionBuilder) Build(dbType DBType) (string, []interface{})
- func (cb *ConditionBuilder) BuildCondition(field any, operator Operator, value any, joiner ...JoinerType) *ConditionBuilder
- func (cb *ConditionBuilder) Or() *ConditionBuilder
- type DBType
- type DataAccess
- type Database
- func (d *Database) AutoMigrate(dst ...interface{}) error
- func (d *Database) Count(count *int64) *Database
- func (d *Database) DB() *gorm.DB
- func (d *Database) Error() error
- func (d *Database) Find(out interface{}) *Database
- func (d *Database) First(out interface{}) *Database
- func (d *Database) Group(group string) *Database
- func (d *Database) Having(builder *ConditionBuilder) *Database
- func (d *Database) Joins(query string, args ...interface{}) *Database
- func (d *Database) Last(out interface{}) *Database
- func (d *Database) Limit(page, pageSize int) *Database
- func (d *Database) Model(model interface{}) *Database
- func (d *Database) Order(order string) *Database
- func (d *Database) Scan(out interface{}) *Database
- func (d *Database) Select(fields ...any) *Database
- func (d *Database) Table(name string) *Database
- func (d *Database) Use(db *gorm.DB) *Database
- func (d *Database) Where(builder *ConditionBuilder) *Database
- type Field
- func Avg(field string) *Field
- func Concat(fields ...string) *Field
- func Count(field string) *Field
- func CountDistinct(field string) *Field
- func DateFormat(field string) *Field
- func Length(field string) *Field
- func Lower(field string) *Field
- func Max(field string) *Field
- func Min(field string) *Field
- func NewField(name string) *Field
- func Sum(field string) *Field
- func Upper(field string) *Field
- func (f *Field) As(as string) *Field
- func (f *Field) Avg() string
- func (f *Field) Concat() string
- func (f *Field) Count() string
- func (f *Field) CountDistinct() string
- func (f *Field) DateFormat() string
- func (f *Field) GenerateSelectSQL(fp string) string
- func (f *Field) Length() string
- func (f *Field) Lower() string
- func (f *Field) Max() string
- func (f *Field) Min() string
- func (f *Field) Sum() string
- func (f *Field) Upper() string
- type FunctionProvider
- type FunctionType
- type JoinerType
- type MySQLDatabase
- type MysqlOperator
- type Operator
- type OperatorI
- type PostgresDatabase
- type PostgresOperator
- type PostgresProvider
- type QueryFilter
Constants ¶
View Source
const ( TYPE_INT = "int" // 整数类型 TYPE_BIGINT = "bigint" // 长整型 TYPE_DECIMAL = "decimal" // 十进制数 TYPE_NUMERIC = "numeric" // 数值 TYPE_REAL = "real" // 实数 TYPE_DOUBLE = "double" // 双精度浮点数 TYPE_SMALLINT = "smallint" // 短整型 TYPE_BOOLEAN = "boolean" // 布尔型 TYPE_CHAR = "char" // 字符串(定长) TYPE_VARCHAR = "varchar" // 字符串(变长) TYPE_TEXT = "text" // 文本 TYPE_DATE = "date" // 日期 TYPE_TIME = "time" // 时间 TYPE_TIMESTAMP = "timestamp" // 时间戳 TYPE_INTERVAL = "interval" // 时间间隔 TYPE_BYTEA = "bytea" // 二进制数据 TYPE_UUID = "uuid" // UUID TYPE )
View Source
const ( GO_TYPE_UINT = "uint" // 无符号整数类型 GO_TYPE_UINT8 = "uint8" // 无符号 8 位整数类型 GO_TYPE_UINT16 = "uint16" // 无符号 16 位整数类型 GO_TYPE_UINT32 = "uint32" // 无符号 32 位整数类型 GO_TYPE_UINT64 = "uint64" // 无符号 64 位整数类型 GO_TYPE_INT = "int" // 整数类型 -> int GO_TYPE_INT8 = "int8" // 8 位整数类型 -> int8 GO_TYPE_INT16 = "int16" // 16 位整数类型 -> int16 GO_TYPE_INT32 = "int32" // 32 位整数类型 -> int32 GO_TYPE_INT64 = "int64" // 64 位整数类型 -> int64 GO_TYPE_FLOAT32 = "float32" // 单精度浮点数 -> float32 GO_TYPE_FLOAT64 = "float64" // 双精度浮点数 -> float64 GO_TYPE_BOOLEAN = "bool" // 布尔型 -> bool GO_TYPE_STRING = "string" // 文本 -> string GO_TYPE_TIME = "time.Time" // 时间 -> time.Time 或者自定义的 Time 类型 GO_TYPE_INTERVAL = "time.Duration" // 时间间隔 -> time.Duration 或者自定义的 Interval 类型 GO_TYPE_BYTEA = "[]byte" // 二进制数据 -> []byte GO_TYPE_UUID = "string" // UUID -> string 或者自定义的 UUID 类型 GO_TYPE_SQL_NULL_TIME = "sql.NullTime" // SQL 空时间 -> sql.NullTime )
Variables ¶
View Source
var OperatorMap = map[DBType]OperatorI{}
Functions ¶
func GetFunctionHandlerSQL ¶
func GetFunctionHandlerSQL(function FunctionType, fp FunctionProvider) string
func GetFunctionSQL ¶
func GetFunctionSQL(function FunctionType) string
GetFunctionSQL 获取 functionMap 中的值
func IsConstantTypeSupported ¶
IsConstantTypeSupported 检查常量类型是否受支持
func IsDatabaseTypeSupported ¶
IsDatabaseTypeSupported 检查数据库类型是否受支持
func IsFunctionTypeValid ¶
func IsFunctionTypeValid(function FunctionType) bool
IsFunctionTypeValid 判断是否在该 map 中
func RegisterDatabase ¶
func RegisterDatabase(dbType DBType, dataAccess DataAccess)
RegisterDatabase 注册不同数据库类型的方法
func RegisterFunctionProvider ¶
func RegisterFunctionProvider(dbType DBType, dataAccess FunctionProvider)
RegisterFunctionProvider 注册不同数据库类型的函数方法
func RegisterOperator ¶
Types ¶
type ClickHouseDatabase ¶
type ClickHouseDatabase struct {
DataAccess
}
ClickHouseDatabase 结构体实现 ClickHouse 数据库访问方法
type ClickhouseOperator ¶
type ClickhouseOperator struct {
OperatorI
}
func (*ClickhouseOperator) Blank ¶
func (co *ClickhouseOperator) Blank(condition Condition, qf *QueryFilter)
func (*ClickhouseOperator) BuildQuery ¶
func (co *ClickhouseOperator) BuildQuery(condition Condition, qf *QueryFilter)
func (*ClickhouseOperator) Equals ¶
func (co *ClickhouseOperator) Equals(condition Condition, qf *QueryFilter)
Equals 等于
func (*ClickhouseOperator) NotBlank ¶
func (co *ClickhouseOperator) NotBlank(condition Condition, qf *QueryFilter)
func (*ClickhouseOperator) NotEqual ¶
func (co *ClickhouseOperator) NotEqual(condition Condition, qf *QueryFilter)
type Condition ¶
type Condition struct { Field any // 字段名 Key string Operator Operator // 操作符 Value interface{} // 值 Joiner JoinerType // 条件连接词:AND 或 OR SubGroups []Condition // 子条件组 }
Condition 条件结构体
func NewCondition ¶
func NewCondition() *Condition
func (*Condition) SetSubGroups ¶
type ConditionBuilder ¶
type ConditionBuilder struct {
// contains filtered or unexported fields
}
ConditionBuilder 用于生成 SQL 条件语句的结构体
func NewConditionBuilder ¶
func NewConditionBuilder() *ConditionBuilder
func (*ConditionBuilder) AddCondition ¶
func (cb *ConditionBuilder) AddCondition(condition Condition) *ConditionBuilder
AddCondition 方法用于添加条件
func (*ConditionBuilder) And ¶
func (cb *ConditionBuilder) And() *ConditionBuilder
And 方法用于设置 AND 连接词
func (*ConditionBuilder) Append ¶
func (cb *ConditionBuilder) Append(builder ConditionBuilder)
Append 方法用于添加条件
func (*ConditionBuilder) Build ¶
func (cb *ConditionBuilder) Build(dbType DBType) (string, []interface{})
Build 方法用于生成 SQL 条件语句
func (*ConditionBuilder) BuildCondition ¶
func (cb *ConditionBuilder) BuildCondition(field any, operator Operator, value any, joiner ...JoinerType) *ConditionBuilder
BuildCondition AddCondition 方法用于添加条件
type DataAccess ¶
type DataAccess interface { Table(db *gorm.DB, name string) *gorm.DB Find(db *gorm.DB, out interface{}) *gorm.DB First(db *gorm.DB, out interface{}) *gorm.DB Last(db *gorm.DB, out interface{}) *gorm.DB Count(db *gorm.DB, count *int64) *gorm.DB Select(db *gorm.DB, fields []Field) *gorm.DB Limit(db *gorm.DB, page, pageSize int64) *gorm.DB Group(db *gorm.DB, group string) *gorm.DB Order(db *gorm.DB, order string) *gorm.DB }
DataAccess 数据访问接口
func GetDataAccess ¶
func GetDataAccess(dbType DBType) DataAccess
GetDataAccess 方法根据外部传入的数据库类型执行相应的操作
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database 结构体定义
func (*Database) AutoMigrate ¶
AutoMigrate 创建表 AutoMigrate 创建表
func (*Database) Having ¶
func (d *Database) Having(builder *ConditionBuilder) *Database
Having having条件查询
type Field ¶
type Field struct { Name string // 字段名 Alias string //别名 // contains filtered or unexported fields }
Field 结构表示一个字段,可能包含聚合函数
func CountDistinct ¶
func DateFormat ¶
func (*Field) CountDistinct ¶
func (*Field) DateFormat ¶
func (*Field) GenerateSelectSQL ¶
GenerateSelectSQL 生成 SELECT 语句
type FunctionProvider ¶
type FunctionProvider interface { Max() string Min() string Count() string CountDistinct() string Avg() string Sum() string DateFormat() string Upper() string Lower() string Concat() string Length() string }
FunctionProvider 接口定义了一个获取函数的方法
func GetDataFunctionProvider ¶
func GetDataFunctionProvider(dbType DBType) FunctionProvider
type FunctionType ¶
type FunctionType string
const ( MaxFunc FunctionType = "max" MinFunc FunctionType = "min" CountFunc FunctionType = "count" CountDistinctFunc FunctionType = "count_distinct" AvgFunc FunctionType = "avg" SumFunc FunctionType = "sum" DateFormatFunc FunctionType = "date_format" UpperFunc FunctionType = "upper" LowerFunc FunctionType = "lower" ConcatFunc FunctionType = "concat" LengthFunc FunctionType = "length" // MySQL中为length,PostgresSQL中为LENGTH )
常量定义
type MysqlOperator ¶
type MysqlOperator struct {
OperatorI
}
func (MysqlOperator) BuildQuery ¶
func (m MysqlOperator) BuildQuery(condition Condition, qf *QueryFilter)
func (MysqlOperator) Equal ¶
func (m MysqlOperator) Equal(condition Condition, qf *QueryFilter)
func (MysqlOperator) GreaterThan ¶
func (m MysqlOperator) GreaterThan(condition Condition, qf *QueryFilter)
func (MysqlOperator) NotEqual ¶
func (m MysqlOperator) NotEqual(condition Condition, qf *QueryFilter)
type Operator ¶
type Operator string
const ( Equal Operator = "equal" NotEqual Operator = "notEqual" GreaterThan Operator = "greaterThan" LessThan Operator = "lessThan" Like Operator = "like" In Operator = "in" NotIn Operator = "notIn" IsNull Operator = "isNull" IsNotNull Operator = "isNotNull" NotLike Operator = "notLike" NotBetween Operator = "notBetween" Between Operator = "between" )
操作符常量
type OperatorI ¶
type OperatorI interface {
BuildQuery(condition Condition, query *QueryFilter)
}
OperatorI 定义了操作符接口
func GetOperatorI ¶
type PostgresDatabase ¶
type PostgresDatabase struct { DataAccess PostgresOperator }
type PostgresOperator ¶
type PostgresOperator struct {
OperatorI
}
func (PostgresOperator) BuildQuery ¶
func (m PostgresOperator) BuildQuery(condition Condition, qf *QueryFilter)
func (PostgresOperator) Equal ¶
func (m PostgresOperator) Equal(condition Condition, qf *QueryFilter)
func (PostgresOperator) NotEqual ¶
func (m PostgresOperator) NotEqual(condition Condition, qf *QueryFilter)
type PostgresProvider ¶
type PostgresProvider struct {
Field
}
func (*PostgresProvider) Length ¶
func (p *PostgresProvider) Length() string
func (*PostgresProvider) Max ¶
func (p *PostgresProvider) Max() string
type QueryFilter ¶
func (*QueryFilter) And ¶
func (qf *QueryFilter) And(query string, args ...any) *QueryFilter
func (*QueryFilter) Or ¶
func (qf *QueryFilter) Or(query string, args ...any) *QueryFilter
Click to show internal directories.
Click to hide internal directories.