Documentation
¶
Index ¶
- Variables
- type BaseDatabase
- type HookAfterDelete
- type HookAfterInsert
- type HookAfterSelect
- type HookAfterUpdate
- type HookBeforeDelete
- type HookBeforeInsert
- type HookBeforeSelect
- type HookBeforeUpdate
- type Session
- func (own *Session) Begin() (err error)
- func (own *Session) COUNT(column ...string) (int64, result.Result, error)
- func (own *Session) CallMethod(method string, value any) error
- func (own *Session) Close() error
- func (own *Session) Commit() (err error)
- func (own *Session) CreateTable(metadata ...dialect.TableMetadata) error
- func (own *Session) DELETE(value ...any) (result.Result, error)
- func (own *Session) DUPLICATE(columns ...string) *Session
- func (own *Session) DeleteTable() error
- func (own *Session) Exec(sql string, args ...any) (sql.Result, error)
- func (own *Session) ExecContext(ctx context.Context, sql string, args ...any) (sql.Result, error)
- func (own *Session) ExistsTable() bool
- func (own *Session) FROM(table string) *Session
- func (own *Session) GROUP(columns ...string) *Session
- func (own *Session) GetDatabase() BaseDatabase
- func (own *Session) GetID() uint64
- func (own *Session) GetSchema() (*schema.Schema, error)
- func (own *Session) HAVING(condition where.Condition) *Session
- func (own *Session) INSERT(ignore bool, values ...any) (result.Result, error)
- func (own *Session) LIMIT(limit int) *Session
- func (own *Session) OFFSET(offset int) *Session
- func (own *Session) ORDER(columns ...string) *Session
- func (own *Session) Query(sql string, args ...any) (*sql.Rows, error)
- func (own *Session) QueryContext(ctx context.Context, sql string, args ...any) (*sql.Rows, error)
- func (own *Session) QueryRow(sql string, args ...any) *sql.Row
- func (own *Session) QueryRowContext(ctx context.Context, sql string, args ...any) *sql.Row
- func (own *Session) Rollback() (err error)
- func (own *Session) SELECT(values any) (res result.Result, err error)
- func (own *Session) SetDebug(color bool)
- func (own *Session) SetSchema(sch *schema.Schema)
- func (own *Session) SetTimeout(timeout time.Duration)
- func (own *Session) UPDATE(values any) (result.Result, error)
- func (own *Session) UseModel(model any) *Session
- func (own *Session) WHERE(condition where.Condition) *Session
- type Stmt
- func (own *Stmt) Exec(id uint64, debug, debugColor bool, args ...any) (sql.Result, error)
- func (own *Stmt) ExecContext(ctx context.Context, id uint64, debug, debugColor bool, args ...any) (sql.Result, error)
- func (own *Stmt) Query(id uint64, debug, debugColor bool, args ...any) (*sql.Rows, error)
- func (own *Stmt) QueryContext(ctx context.Context, id uint64, debug, debugColor bool, args ...any) (*sql.Rows, error)
- func (own *Stmt) QueryRow(id uint64, debug, debugColor bool, args ...any) *sql.Row
- func (own *Stmt) QueryRowContext(ctx context.Context, id uint64, debug, debugColor bool, args ...any) *sql.Row
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrTableNoPK = errors.New("worm: table no primary key") ErrTablePKValuesZero = errors.New("worm: values of primary keys are zero") ErrMissingWhere = errors.New("worm: requires WHERE clause, use .WHERE() first") ErrInsertValuesEmpty = errors.New("worm: insert values are empty") ErrUpdateValuesNil = errors.New("worm: update values are nil") ErrUpdateMapEmpty = errors.New("worm: update map is empty") ErrSelectValueNil = errors.New("worm: select values are nil") ErrSelectValuesNotPointer = errors.New("worm: select values must be pointer, eg: *Struct, *[]Struct, *[]*Struct") ErrSelectDestinationValueInvalid = errors.New("worm: select destination value is invalid") ErrSelectDestinationValueNotSettable = errors.New("worm: select destination value is not settable") ErrSelectDestinationSliceNotSettable = errors.New("worm: select destination slice is not settable") )
View Source
var ( ErrModelNotSpecified = errors.New("worm: data model is not be specified") ErrModelNoExportableFields = errors.New("worm: data model has no exportable fields") )
Functions ¶
This section is empty.
Types ¶
type BaseDatabase ¶
type BaseDatabase interface {
Exec(sql string, args ...any) (sql.Result, error)
ExecContext(ctx context.Context, sql string, args ...any) (sql.Result, error)
Query(sql string, args ...any) (*sql.Rows, error)
QueryContext(ctx context.Context, sql string, args ...any) (*sql.Rows, error)
QueryRow(sql string, args ...any) *sql.Row
QueryRowContext(ctx context.Context, sql string, args ...any) *sql.Row
}
BaseDatabase 定义数据库操作的基本接口
type HookAfterDelete ¶
HookAfterDelete 在删除数据之后调用
type HookAfterInsert ¶
HookAfterInsert 在插入数据之后调用
type HookAfterSelect ¶
HookAfterSelect 在查询数据之后调用
type HookAfterUpdate ¶
HookAfterUpdate 在更新数据之后调用
type HookBeforeDelete ¶
HookBeforeDelete 在删除数据之前调用
type HookBeforeInsert ¶
HookBeforeInsert 在插入数据之前调用
type HookBeforeSelect ¶
HookBeforeSelect 在查询数据之前调用
type HookBeforeUpdate ¶
HookBeforeUpdate 在更新数据之前调用
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session 数据库的连接会话
func (*Session) CallMethod ¶
CallMethod 调用钩子函数
func (*Session) CreateTable ¶
func (own *Session) CreateTable(metadata ...dialect.TableMetadata) error
CreateTable 创建数据表
func (*Session) DELETE ¶
DELETE 删除数据
- value: 支持格式 map[[string]]any、struct、*struct
- 注意:若使用 struct 或 *struct 参数时,若没有 WHERE 条件,则主动使用主键作为 WHERE 条件,若主键均为零值,则返回错误
func (*Session) ExecContext ¶
ExecContext 执行带上下文的 SQL 语句
func (*Session) GetDatabase ¶
func (own *Session) GetDatabase() BaseDatabase
GetDatabase 返回 *sql.DB 或 *sql.TX
func (*Session) INSERT ¶
INSERT 插入单条或多条数据到数据表
- ignore: 插入语句 INSERT IGNORE INTO ...
- values: 支持格式 ...Struct 或 ...*Struct
func (*Session) QueryContext ¶
QueryContext 执行带上下文的 SQL 查询语句,返回多条结果
func (*Session) QueryRowContext ¶
QueryRowContext 执行带上下文的 SQL 查询语句,返回单条结果
func (*Session) SetTimeout ¶
SetTimeout 设置执行 SQL 语句的超时时间
func (*Session) UPDATE ¶
UPDATE 更新数据
- values: 支持格式 map[[string]]any、struct、*struct
- 注意1:若传入结构体且没有手动设置 WHERE 子句,则内部使用主键自动构建 WHERE 子句,此时,数据模型必须定义主键字段,且模型实例中必须设置主键字段的值
- 注意2:map[[string]]any 更新不支持钩子函数,也不自动构建 WHERE 子句,请自行调用 WHERE 方法
Click to show internal directories.
Click to hide internal directories.