sqlbuilder

package module
v0.0.5 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

This section is empty.

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 RegisterArgsHandle added in v0.0.5

func RegisterArgsHandle(n int, obj IArgser)

*

  • 注册参数处理函数

func RegisterSymbol

func RegisterSymbol(operater string, obj IOperater)

func SField

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

*

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

Types

type Condition

type Condition struct {

	// 字段
	Field string

	FieldType int64

	// 条件
	Condition string

	// 值
	Value interface{}

	// 表
	TableName string

	// 关系
	Relation string
}

条件结构体

type GroupWhere

type GroupWhere struct {
	Relation  string
	Condition []Condition
}

type IArgser

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

type IOperater

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

运算符号接口

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