sqlbuilder

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

README

sqlbuilder

sql 构造器,配合sqlx使用

test 文件有使用示例

Documentation

Index

Constants

View Source
const (
	LIKE         = "like"
	NLIKE        = "not like"
	START_WITH   = "start with"
	NSTART_WITH  = "not start with"
	END_WITH     = "end with"
	NEND_WITH    = "not end with"
	IN           = "in"
	NIN          = "not in"
	BETWEEN      = "between"
	NBETWEEN     = "not between"
	EQUAL        = "="
	NEQUAL       = "!="
	GT           = ">"
	LT           = "<"
	GTE          = ">="
	LTE          = "<="
	IS_NULL      = "is null"
	IS_NOT_NULL  = "is not null"
	IS_EMPTY     = "is empty"
	IS_NOT_EMPTY = "is not empty"
)

Variables

View Source
var ArgsMap map[int]IArgser
View Source
var SymbolMap map[string]IOperater

Functions

func Fn

func Fn(fn, alias string, params ...interface{}) *funCarrier

*

  • 使用mysql函数
  • 避免使用本函数来拼接用户提交的数据
  • fn 表示函数名,如:sum,max,min,count,avg
  • alias 表示别名
  • params 表示函数参数

func From

func From(tableName string, args ...interface{}) *sqlBuilder

From 用于创建一个 sqlBuilder 实例,并返回该实例的指针。 参数 tableName 表示表名。 返回值为 *sqlBuilder 指针,指向新创建的 sqlBuilder 实例。

func Literal added in v0.0.4

func Literal(originVal string) *literalCarrier

*

  • 使用原语
  • 避免使用本函数来拼接用户提交的数据

func RegisterSymbol

func RegisterSymbol(operater string, obj IOperater)

func SField

func SField(tableAlias, field, fieldAlias string) *colCarrier

*

  • 查询指定表的字段
  • 避免使用本函数来拼接用户提交的数据

Types

type BetweenOp

type BetweenOp struct {
	Symbol string
}

func (*BetweenOp) Operate

func (r *BetweenOp) Operate(w Condition) (string, string, []interface{})

type Condition

type Condition struct {

	// 字段
	Field string

	FieldType int64

	// 条件
	Condition string

	// 值
	Value interface{}

	// 表
	TableName string

	// 关系
	Relation string
}

条件结构体

type EndWithOp

type EndWithOp struct {
	Symbol string
}

func (*EndWithOp) Operate

func (r *EndWithOp) Operate(w Condition) (string, string, []interface{})

type EqualOp

type EqualOp struct {
	Symbol string
}

func (*EqualOp) Operate

func (r *EqualOp) Operate(w Condition) (string, string, []interface{})

type FiveArgs

type FiveArgs struct {
}

func (*FiveArgs) ParseArgs

func (r *FiveArgs) ParseArgs(relation string, args ...interface{}) []GroupWhere

type FourArgs

type FourArgs struct {
}

func (*FourArgs) ParseArgs

func (r *FourArgs) ParseArgs(relation string, args ...interface{}) []GroupWhere

type GroupWhere

type GroupWhere struct {
	Relation  string
	Condition []Condition
}

type GtOp

type GtOp struct {
	Symbol string
}

func (*GtOp) Operate

func (r *GtOp) Operate(w Condition) (string, string, []interface{})

type IArgser

type IArgser interface {
	ParseArgs(relation string, args ...interface{}) []GroupWhere
}

type IOperater

type IOperater interface {
	Operate(w Condition) (string, string, []interface{})
}

运算符号接口

type InOp

type InOp struct {
	Symbol string
}

func (*InOp) Operate

func (r *InOp) Operate(w Condition) (string, string, []interface{})

type IsEmptyOp

type IsEmptyOp struct {
	Symbol string
}

func (*IsEmptyOp) Operate

func (r *IsEmptyOp) Operate(w Condition) (string, string, []interface{})

type IsNullOp

type IsNullOp struct {
	Symbol string
}

func (*IsNullOp) Operate

func (r *IsNullOp) Operate(w Condition) (string, string, []interface{})

type LikeOp

type LikeOp struct {
	Symbol string
}

func (*LikeOp) Operate

func (r *LikeOp) Operate(w Condition) (string, string, []interface{})

type LtOp

type LtOp struct {
	Symbol string
}

func (*LtOp) Operate

func (r *LtOp) Operate(w Condition) (string, string, []interface{})

type OneArgs

type OneArgs struct {
}

func (*OneArgs) ParseArgs

func (r *OneArgs) ParseArgs(relation string, args ...interface{}) []GroupWhere

type StartWithOp

type StartWithOp struct {
	Symbol string
}

func (*StartWithOp) Operate

func (r *StartWithOp) Operate(w Condition) (string, string, []interface{})

type ThreeArgs

type ThreeArgs struct {
}

func (*ThreeArgs) ParseArgs

func (r *ThreeArgs) ParseArgs(relation string, args ...interface{}) []GroupWhere

type TwoArgs

type TwoArgs struct {
}

func (*TwoArgs) ParseArgs

func (r *TwoArgs) ParseArgs(relation string, args ...interface{}) []GroupWhere

type Where

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

func (*Where) ParseWhere

func (r *Where) ParseWhere() (string, []interface{})

实现where接口

func (*Where) SetAlias

func (r *Where) SetAlias(alias string)

设置表别名

func (*Where) SetGroup

func (r *Where) SetGroup()

func (*Where) SetGroupWhere

func (r *Where) SetGroupWhere(groupWhere []GroupWhere)

func (*Where) SetTableName

func (r *Where) SetTableName(tableName string)

设置表名

Jump to

Keyboard shortcuts

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