Documentation
¶
Overview ¶
Package engine provides an xorm-compatible API layer for hanzo/orm.
Type conversion uses standard encoding/json — no custom parsers, no whitespace bugs. This fixes the xorm v1.1.6 issue where JSON []string with spaces after commas fails to deserialize.
Index ¶
- func Between(col string, low, high interface{}) condition
- func Eq(col string, value interface{}) condition
- func Expr(sql string, args ...interface{}) condition
- func Gt(col string, value interface{}) condition
- func Gte(col string, value interface{}) condition
- func In(col string, args ...interface{}) condition
- func IsNotNull(col string) condition
- func IsNull(col string) condition
- func Like(col string, pattern string) condition
- func Lt(col string, value interface{}) condition
- func Lte(col string, value interface{}) condition
- func Neq(col string, value interface{}) condition
- func NotIn(col string, args ...interface{}) condition
- type Builder
- type ColumnMeta
- type Cond
- type Engine
- func (e *Engine) Close() error
- func (e *Engine) Count(bean ...interface{}) (int64, error)
- func (e *Engine) DB() *sql.DB
- func (e *Engine) Delete(bean interface{}) (int64, error)
- func (e *Engine) DriverName() string
- func (e *Engine) Exec(sqlOrArgs ...interface{}) (sql.Result, error)
- func (e *Engine) Find(beans interface{}, conds ...interface{}) error
- func (e *Engine) Get(bean interface{}) (bool, error)
- func (e *Engine) ID(pk interface{}) *Session
- func (e *Engine) Insert(beans ...interface{}) (int64, error)
- func (e *Engine) NewSession() *Session
- func (e *Engine) Ping() error
- func (e *Engine) Query(sqlOrArgs ...interface{}) ([]map[string][]byte, error)
- func (e *Engine) SQL(query string, args ...interface{}) *Session
- func (e *Engine) SetColumnMapper(mapper names.Mapper)
- func (e *Engine) SetMapper(mapper names.Mapper)
- func (e *Engine) SetTableMapper(mapper names.Mapper)
- func (e *Engine) ShowSQL(show bool)
- func (e *Engine) Sync2(beans ...interface{}) error
- func (e *Engine) Table(name string) *TableMeta
- func (e *Engine) Transaction(fn func(*Session) (interface{}, error)) (interface{}, error)
- func (e *Engine) Update(bean interface{}, conds ...interface{}) (int64, error)
- func (e *Engine) Where(query string, args ...interface{}) *Session
- type PK
- type Session
- func (s *Session) Alias(alias string) *Session
- func (s *Session) AllCols() *Session
- func (s *Session) And(query string, args ...interface{}) *Session
- func (s *Session) Asc(colNames ...string) *Session
- func (s *Session) Begin() error
- func (s *Session) Close()
- func (s *Session) Cols(cols ...string) *Session
- func (s *Session) Commit() error
- func (s *Session) Context(ctx context.Context) *Session
- func (s *Session) Count(bean ...interface{}) (int64, error)
- func (s *Session) Delete(bean interface{}) (int64, error)
- func (s *Session) Desc(colNames ...string) *Session
- func (s *Session) Exec(sqlOrArgs ...interface{}) (sql.Result, error)
- func (s *Session) Exist(bean ...interface{}) (bool, error)
- func (s *Session) Find(beans interface{}, conds ...interface{}) error
- func (s *Session) Get(bean interface{}) (bool, error)
- func (s *Session) GroupBy(keys string) *Session
- func (s *Session) Having(cond string) *Session
- func (s *Session) ID(pk interface{}) *Session
- func (s *Session) In(col string, args ...interface{}) *Session
- func (s *Session) Insert(beans ...interface{}) (int64, error)
- func (s *Session) Join(joinType, tableName string, cond string, args ...interface{}) *Session
- func (s *Session) Limit(limit int, start ...int) *Session
- func (s *Session) NotIn(col string, args ...interface{}) *Session
- func (s *Session) Omit(cols ...string) *Session
- func (s *Session) Or(query string, args ...interface{}) *Session
- func (s *Session) OrderBy(order string) *Session
- func (s *Session) Prepare() *Session
- func (s *Session) QueryBytes(sqlOrArgs ...interface{}) ([]map[string][]byte, error)
- func (s *Session) Rollback() error
- func (s *Session) SQL(query string, args ...interface{}) *Session
- func (s *Session) Select(str string) *Session
- func (s *Session) Table(name interface{}) *Session
- func (s *Session) Update(bean interface{}, conds ...interface{}) (int64, error)
- func (s *Session) Where(query string, args ...interface{}) *Session
- type TableMeta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Between ¶
func Between(col string, low, high interface{}) condition
Between creates a BETWEEN condition.
func Eq ¶
func Eq(col string, value interface{}) condition
Eq creates an equality condition: col = value.
func Expr ¶
func Expr(sql string, args ...interface{}) condition
Expr creates a raw SQL expression condition.
func Gt ¶
func Gt(col string, value interface{}) condition
Gt creates a greater-than condition: col > value.
func Gte ¶
func Gte(col string, value interface{}) condition
Gte creates a greater-than-or-equal condition: col >= value.
func In ¶
func In(col string, args ...interface{}) condition
In creates an IN condition for use with Session.Where().
func Lt ¶
func Lt(col string, value interface{}) condition
Lt creates a less-than condition: col < value.
func Lte ¶
func Lte(col string, value interface{}) condition
Lte creates a less-than-or-equal condition: col <= value.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder assembles SQL queries with proper parameter binding.
func NewBuilder ¶
NewBuilder creates a builder for the given driver.
func (*Builder) WriteArg ¶
func (b *Builder) WriteArg(arg interface{})
WriteArg appends a placeholder and records the argument.
func (*Builder) WriteString ¶
WriteString appends raw SQL text.
type ColumnMeta ¶
type ColumnMeta struct {
Name string
GoName string
GoType reflect.Type
SQLType string
IsPrimaryKey bool
IsAutoIncr bool
IsNullable bool
IsUnique bool
IsCreated bool // auto-set on insert
IsUpdated bool // auto-set on update
IsDeleted bool // soft-delete
IsVersion bool // optimistic lock
IsJSON bool // stored as JSON text
Default string
Length int
Index string // index name, empty = no index
}
ColumnMeta holds metadata for a single column.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the xorm-compatible entrypoint. It wraps a *sql.DB and provides table registration, schema sync, and Session creation.
func NewEngineWithDB ¶
NewEngineWithDB creates an Engine from an existing *sql.DB.
func (*Engine) DriverName ¶
DriverName returns the normalized driver name.
func (*Engine) NewSession ¶
NewSession creates a new session for this engine.
func (*Engine) SetColumnMapper ¶
SetColumnMapper sets the column name mapper.
func (*Engine) SetTableMapper ¶
SetTableMapper sets the table name mapper.
func (*Engine) Sync2 ¶
Sync2 synchronizes table schemas from struct definitions. Creates tables if they don't exist, adds missing columns.
func (*Engine) Transaction ¶
Transaction runs fn inside a transaction. If fn returns nil the tx is committed; otherwise it is rolled back.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session provides the xorm-compatible fluent query/mutation API.
func (*Session) Close ¶
func (s *Session) Close()
Close is a no-op for session (for xorm compatibility).
func (*Session) QueryBytes ¶
QueryBytes executes raw SQL and returns []map[string][]byte.
type TableMeta ¶
type TableMeta struct {
Name string
Columns []*ColumnMeta
PrimaryKey []string // column names
// contains filtered or unexported fields
}
TableMeta holds metadata for a table.
func (*TableMeta) Column ¶
func (t *TableMeta) Column(name string) *ColumnMeta
Column returns a column by name.