Documentation ¶
Index ¶
- Variables
- func NewCreate(ctx context.Context, drv dialect.Driver, spec *CreateSpec) error
- func NewDelete(ctx context.Context, drv dialect.Driver, spec *DeleteSpec) error
- func NewQuery(ctx context.Context, drv dialect.Driver, spec *QuerySpec) error
- func NewQueryContext(parent context.Context, c *QueryContext) context.Context
- func NewUpdate(ctx context.Context, drv dialect.Driver, spec *UpdateSpec) error
- type Builder
- func (b *Builder) Arg(a any) *Builder
- func (b *Builder) Argf(format string, a any) *Builder
- func (b *Builder) Args(args ...any) *Builder
- func (b *Builder) Blank() *Builder
- func (b *Builder) Comma() *Builder
- func (b Builder) Dialect() dialect.DbDriver
- func (b *Builder) Ident(s string) *Builder
- func (b *Builder) IdentComma(s ...string) *Builder
- func (b *Builder) Join(qs ...Querier) *Builder
- func (b *Builder) Len() int
- func (b *Builder) Quote(ident string) string
- func (b *Builder) Reset()
- func (b *Builder) SetDialect(dialect dialect.DbDriver)
- func (b *Builder) SetTotal(total int)
- func (b *Builder) String() string
- func (b Builder) Total() int
- func (b *Builder) Wrap(f func(*Builder)) *Builder
- func (b *Builder) WriteByte(c byte) *Builder
- func (b *Builder) WriteOp(op Op) *Builder
- func (b *Builder) WriteSchema(schema string) *Builder
- func (b *Builder) WriteString(s string) *Builder
- type CreateSpec
- type DeleteSpec
- type Deleter
- type DialectBuilder
- type EntitySpec
- type Field
- type FieldName
- type FieldSpec
- type Inserter
- func (i *Inserter) Insert() (string, []any)
- func (i *Inserter) Set(column string, v any) *Inserter
- func (i *Inserter) SetDialect(dialect dialect.DbDriver) *Inserter
- func (i *Inserter) SetEntity(entity string) *Inserter
- func (i *Inserter) SetReturning(returning ...FieldName) *Inserter
- func (i *Inserter) SetSchema(schema string) *Inserter
- type Op
- type ParamFormatter
- type Predicate
- type Querier
- type QueryContext
- type QueryContextKey
- type QuerySpec
- type Scanner
- type Selection
- type Selector
- func (s *Selector) Query() (string, []any)
- func (s *Selector) Rows(rows ...FieldName) []string
- func (s *Selector) SetContext(ctx context.Context) *Selector
- func (s *Selector) SetDialect(dialect dialect.DbDriver) *Selector
- func (s *Selector) SetFrom(from string) *Selector
- func (s *Selector) SetLimit(limit int) *Selector
- func (s *Selector) SetSelect(rows ...string) *Selector
- type StmtInfo
- type UpdateSpec
- type Updater
Constants ¶
This section is empty.
Variables ¶
View Source
var OpAnd = func(p *Predicate) {
p.And()
}
View Source
var OpNot = func(p *Predicate) {
p.Not()
}
View Source
var OpOr = func(p *Predicate) {
p.Or()
}
Functions ¶
func NewQueryContext ¶
func NewQueryContext(parent context.Context, c *QueryContext) context.Context
NewQueryContext 将QueryContext添加到context中,并返回一个新的context。
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func (*Builder) Argf ¶
Argf 将输入参数以给定的格式添加到生成器中。
Argf("JSON(?)", b). Argf("ST_GeomFromText(?)", geom)
func (*Builder) IdentComma ¶
IdentComma 添加标识符到查询中,用逗号分隔
func (*Builder) SetDialect ¶
SetDialect 设置生成器使用的数据库驱动。满足state接口。
func (*Builder) WriteSchema ¶
WriteSchema 添加一个模式到查询中。
func (*Builder) WriteString ¶
WriteString 添加一个字符串到查询中。
type CreateSpec ¶
type CreateSpec struct { Entity *EntitySpec Scan Scanner Fields []*FieldSpec Returning []FieldName // TODO Schema string }
func NewCreateSpec ¶
func NewCreateSpec(entity string, rows []FieldName) *CreateSpec
func (*CreateSpec) CheckRequired ¶
func (s *CreateSpec) CheckRequired(name FieldName, f entity.FieldStorager) error
CheckRequired 检查字段是否为空。
type DeleteSpec ¶
type DeleteSpec struct { Entity *EntitySpec Predicate func(*Predicate) Affected *int64 }
func NewDeleteSpec ¶
func NewDeleteSpec(entity string) *DeleteSpec
type DialectBuilder ¶
type DialectBuilder struct {
// contains filtered or unexported fields
}
func NewDialect ¶
func NewDialect(dialect dialect.DbDriver) *DialectBuilder
func (*DialectBuilder) Select ¶
func (b *DialectBuilder) Select() *Selector
type EntitySpec ¶
type Inserter ¶
type Inserter struct { Builder // contains filtered or unexported fields }
func (*Inserter) SetReturning ¶
type Op ¶
type Op int
type ParamFormatter ¶
type ParamFormatter interface { // 这个接口可以被用于特定的场景, // 例如当你使用的数据库需要一种特殊的参数格式时。 // 例子:如果你在MySQL中使用地理空间数据, // 你可能需要将标准的参数占位符(如?)转换为特定的函数调用(如ST_GeomFromWKB(?))。 // 参数 // - placeholder: 标准的占位符,如? // - info: 保存SQL语句或数据库连接的上下文信息 FormatParam(placeholder string, info *StmtInfo) string }
ParamFormatter 定义了FormatParam方法,用于格式化占位符。
type Querier ¶
第一个对象返回:("SELECT * FROM users WHERE age > ?", [30]) 第二个对象返回:("AND name = ?", ["John"]) 当使用 Join 方法将这两个对象组合时,生成的SQL查询将是: SELECT * FROM users WHERE age > ? AND name = ?
type QueryContext ¶
type QueryContext struct { // Limit 限制查询语句返回的记录数。 // 调用Limit方法时,会将Limit设置为指定的值。 // 比如:Limit(10), sql: Select * from user limit 10。 Limit *int Fields []FieldName }
QueryContext 用于Query,包含了查询语句上下的信息, 比如Limit、Offset、Order等,用于生成查询语句。
func QueryFromContext ¶
func QueryFromContext(ctx context.Context) *QueryContext
QueryFromContext 从context中获取QueryContext。
type QueryContextKey ¶
type QueryContextKey struct{}
type QuerySpec ¶
type QuerySpec struct { Entity *EntitySpec Scan Scanner Limit int Predicate func(*Predicate) }
QuerySpec 包含了实体的查询的信息。 通过把Query中的信息转换为QuerySpec,把QuerySpec传给NewQuery发起查询, QuerySpec是把查询信息转为sql的中间件。
type UpdateSpec ¶
type UpdateSpec struct { Entity *EntitySpec Scan Scanner Sets []*FieldSpec Predicate func(*Predicate) }
func NewUpdateSpec ¶
func NewUpdateSpec(entity string, rows []FieldName) *UpdateSpec
Source Files ¶
Click to show internal directories.
Click to hide internal directories.