sqlbuilder

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OpAnd = &op{symbol: "AND", text: " AND "}
	OpOr  = &op{symbol: "OR", text: " OR "}
)
View Source
var (
	SQLErrTableNameRequire = errors.New("[sqlbuilder] tableName requires")
	SQLErrColumnsRequire   = errors.New("[sqlbuilder] columns requires")
	SQLErrDeleteMissWhere  = errors.New("[sqlbuilder] delete sql miss where")
)

Functions

func GetColumnsByModel

func GetColumnsByModel(mapper *reflectx.Mapper, model interface{}, omitColumns ...string) []string

func GetColumnsByType

func GetColumnsByType(mapper *reflectx.Mapper, typ reflect.Type, omitColumns ...string) []string

GetColumnsByType 通过字段 tag 解析数据库字段

func GetMapperByTagName

func GetMapperByTagName(tagName string) *reflectx.Mapper

Types

type Builder

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

func New

func New(tableName string) *Builder

func (*Builder) Delete

func (b *Builder) Delete() *Deleter

func (*Builder) Insert

func (b *Builder) Insert(columns ...string) *Inserter

func (*Builder) Select

func (b *Builder) Select(columns ...string) *Selector

func (*Builder) Update

func (b *Builder) Update(columns ...string) *Updater

type Condition

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

func C

func C() *Condition

C where 条件

func (*Condition) And

func (c *Condition) And(meet bool, express string, args ...interface{}) *Condition

And and 语句 meet 判断是否需要拼接这个where表达式 express where 表达式

func (*Condition) Or

func (c *Condition) Or(meet bool, express string, args ...interface{}) *Condition

Or or 语句 meet 判断是否需要拼接这个where表达式 express where 表达式

func (*Condition) Where

func (c *Condition) Where(meet bool, express string, args ...interface{}) *Condition

Where meet 判断是否需要拼接这个where表达式 express where 表达式

type ConditionBuilder

type ConditionBuilder interface {
	// contains filtered or unexported methods
}

type Deleter

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

func NewDeleter

func NewDeleter(tableName string) *Deleter

NewDeleter tableName 数据库表名

func (*Deleter) SQL

func (d *Deleter) SQL() (string, error)

SQL 输出sql语句

func (*Deleter) SQLArgs

func (d *Deleter) SQLArgs() (string, []interface{}, error)

SQLArgs 构造 sql 并返回对应参数

func (*Deleter) Where

func (d *Deleter) Where(where ConditionBuilder) *Deleter

Where 条件 condition 可以通过 sqlbuilder.C() 方法创建

type Inserter

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

func NewInserter

func NewInserter(tableName string) *Inserter

func (*Inserter) Columns

func (ins *Inserter) Columns(columns ...string) *Inserter

func (*Inserter) IsReplaceInto

func (ins *Inserter) IsReplaceInto(replaceInto bool) *Inserter

func (*Inserter) NameSQL

func (ins *Inserter) NameSQL() (string, error)

func (*Inserter) OnDuplicateKeyUpdateString

func (ins *Inserter) OnDuplicateKeyUpdateString(updateString string) *Inserter

func (*Inserter) SQL

func (ins *Inserter) SQL() (string, error)

func (*Inserter) StructColumns

func (ins *Inserter) StructColumns(m interface{}, tagName string, omitColumns ...string) *Inserter

type OrderBy

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

func Asc

func Asc(columns ...string) OrderBy

func Desc

func Desc(columns ...string) OrderBy

type OrderType

type OrderType string
const (
	ASC  OrderType = "ASC"
	DESC OrderType = "DESC"
)

type Predicate

type Predicate struct {
	Op      *op
	Express string
	Args    []interface{}
}

type Selector

type Selector struct {
	IsForUpdate bool
	// contains filtered or unexported fields
}

func NewSelector

func NewSelector(tableName string) *Selector

func (*Selector) Columns

func (s *Selector) Columns(columns ...string) *Selector

Columns select 的数据库字段

func (*Selector) Distinct

func (s *Selector) Distinct() *Selector

Distinct select distinct

func (*Selector) ForUpdate

func (s *Selector) ForUpdate(isForUpdate bool) *Selector

ForUpdate select for update

func (*Selector) GroupBy

func (s *Selector) GroupBy(columns ...string) *Selector

GroupBy group by

func (*Selector) Limit

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

Limit 分页 limit

func (*Selector) Offset

func (s *Selector) Offset(offset int) *Selector

Offset 分页 offset

func (*Selector) OrderBy

func (s *Selector) OrderBy(orderBy ...OrderBy) *Selector

OrderBy order by orderBy sqlbuilder.Desc("col")

func (*Selector) QueryString

func (s *Selector) QueryString(queryString string) *Selector

QueryString 自定义select字段,sql原样输出

func (*Selector) SQL

func (s *Selector) SQL() (string, error)

SQL 拼接sql语句

func (*Selector) SQLArgs

func (s *Selector) SQLArgs() (string, []interface{}, error)

SQLArgs 构造 sql 并返回对应参数

func (*Selector) StructColumns

func (s *Selector) StructColumns(model interface{}, tagName string, omitColumns ...string) *Selector

StructColumns 通过任意model解析出表字段 tagName 解析数据库字段的 tag-name omitColumns 排除哪些字段

func (*Selector) Where

func (s *Selector) Where(where ConditionBuilder) *Selector

Where 条件 condition 可以通过 sqlbuilder.C() 方法创建

type SimpleCondition

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

SimpleCondition 简单 where 语句

func SC

func SC() *SimpleCondition

SC 简单 where 条件

func (*SimpleCondition) And

func (c *SimpleCondition) And(express string, args ...interface{}) *SimpleCondition

And and 语句 express where 表达式

func (*SimpleCondition) Or

func (c *SimpleCondition) Or(express string, args ...interface{}) *SimpleCondition

Or or 语句 express where 表达式

func (*SimpleCondition) Predicates

func (c *SimpleCondition) Predicates() []*Predicate

func (*SimpleCondition) Where

func (c *SimpleCondition) Where(express string, args ...interface{}) *SimpleCondition

Where express where 表达式

type Updater

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

func NewUpdater

func NewUpdater(tableName string) *Updater

func (*Updater) Columns

func (u *Updater) Columns(columns ...string) *Updater

Columns update 的数据库字段

func (*Updater) NameSQL

func (u *Updater) NameSQL() (string, error)

func (*Updater) SQL

func (u *Updater) SQL() (string, error)

SQL 拼接sql语句

func (*Updater) SQLArgs

func (u *Updater) SQLArgs() (string, []interface{}, error)

SQLArgs 构造 sql 并返回对应参数

func (*Updater) StructColumns

func (u *Updater) StructColumns(model interface{}, tagName string, omitColumns ...string) *Updater

StructColumns 通过任意model解析出表字段 tagName 解析数据库字段的 tag-name omitColumns 排除哪些字段

func (*Updater) Where

func (u *Updater) Where(where ConditionBuilder) *Updater

Where 条件 condition 可以通过 sqlbuilder.C() 方法创建

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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