Documentation
¶
Index ¶
- type Chain
- func (c *Chain) Avg(field string) (float64, error)
- func (c *Chain) BatchInsert(batchSize int) (int64, error)
- func (c *Chain) BatchValues(values []map[string]interface{}) *Chain
- func (c *Chain) Begin() (*Chain, error)
- func (c *Chain) Between(field string, start, end interface{}) *Chain
- func (c *Chain) Commit() error
- func (c *Chain) Count() (int64, error)
- func (c *Chain) Count2(field string) (int64, error)
- func (c *Chain) CreateTable(model interface{}) error
- func (c *Chain) Delete(models ...interface{}) define.Result
- func (c *Chain) Eq(field string, value interface{}) *Chain
- func (c *Chain) Fields(fields ...string) *Chain
- func (c *Chain) First(dest ...interface{}) *QueryResult
- func (c *Chain) From(model interface{}) *Chain
- func (c *Chain) Ge(field string, value interface{}) *Chain
- func (c *Chain) GroupBy(fields ...string) *Chain
- func (c *Chain) Gt(field string, value interface{}) *Chain
- func (c *Chain) Having(condition interface{}, args ...interface{}) *Chain
- func (c *Chain) In(field string, value interface{}) *Chain
- func (c *Chain) Into(dest interface{}) error
- func (c *Chain) IsInTransaction() bool
- func (c *Chain) IsNotNull(field string) *Chain
- func (c *Chain) IsNull(field string) *Chain
- func (c *Chain) Le(field string, value interface{}) *Chain
- func (c *Chain) Like(field string, value interface{}) *Chain
- func (c *Chain) Limit(count int) *Chain
- func (c *Chain) List(dest ...interface{}) *QueryResult
- func (c *Chain) Lt(field string, value interface{}) *Chain
- func (c *Chain) Ne(field string, value interface{}) *Chain
- func (c *Chain) NewCondition() *define.Condition
- func (c *Chain) NotBetween(field string, start, end interface{}) *Chain
- func (c *Chain) NotIn(field string, value interface{}) *Chain
- func (c *Chain) NotLike(field string, value interface{}) *Chain
- func (c *Chain) Offset(count int) *Chain
- func (c *Chain) One(dest ...interface{}) *QueryResult
- func (c *Chain) Or(cond *define.Condition) *Chain
- func (c *Chain) OrBetween(field string, start, end interface{}) *Chain
- func (c *Chain) OrEq(field string, value interface{}) *Chain
- func (c *Chain) OrGe(field string, value interface{}) *Chain
- func (c *Chain) OrGt(field string, value interface{}) *Chain
- func (c *Chain) OrIn(field string, value interface{}) *Chain
- func (c *Chain) OrIsNotNull(field string) *Chain
- func (c *Chain) OrIsNull(field string) *Chain
- func (c *Chain) OrLe(field string, value interface{}) *Chain
- func (c *Chain) OrLike(field string, value interface{}) *Chain
- func (c *Chain) OrLt(field string, value interface{}) *Chain
- func (c *Chain) OrNe(field string, value interface{}) *Chain
- func (c *Chain) OrNotBetween(field string, start, end interface{}) *Chain
- func (c *Chain) OrNotIn(field string, value interface{}) *Chain
- func (c *Chain) OrNotLike(field string, value interface{}) *Chain
- func (c *Chain) OrWhereGroup() *define.Condition
- func (c *Chain) OrderBy(field string) *Chain
- func (c *Chain) OrderByDesc(field string) *Chain
- func (c *Chain) Page(pageNum, pageSize int) *Chain
- func (c *Chain) PageInfo(model interface{}) (*PageInfo, error)
- func (c *Chain) RawExecute(sql string, args ...interface{}) define.Result
- func (c *Chain) RawQuery(sqlStr string, args ...interface{}) *QueryResult
- func (c *Chain) ReleaseSavepoint(name string) error
- func (c *Chain) Rollback() error
- func (c *Chain) RollbackTo(name string) error
- func (c *Chain) Save(models ...interface{}) define.Result
- func (c *Chain) Savepoint(name string) error
- func (c *Chain) Set(field string, value interface{}) *Chain
- func (c *Chain) SetIsolationLevel(level sql.IsolationLevel) *Chain
- func (c *Chain) Sum(field string) (float64, error)
- func (c *Chain) Table(table string) *Chain
- func (c *Chain) Transaction(fn func(*Chain) error) error
- func (c *Chain) Update(fields map[string]interface{}) define.Result
- func (c *Chain) Values(fields map[string]interface{}) *Chain
- func (c *Chain) Where(field string, op define.OpType, value interface{}) *Chain
- func (c *Chain) Where2(cond *define.Condition) *Chain
- func (c *Chain) WhereGroup() *define.Condition
- type DB
- func (db *DB) Begin() (*sql.Tx, error)
- func (db *DB) Chain() *Chain
- func (db *DB) Close() error
- func (db *DB) GenerateStruct(tableName, outputDir, packageName string) error
- func (db *DB) GenerateStructs(opts GenerateOptions) error
- func (db *DB) GetOptions() define.DBOptions
- func (db *DB) GetTableInfo(tableName string) (*define.TableInfo, error)
- func (db *DB) GetTableName(model interface{}) (string, error)
- func (db *DB) GetTables(pattern string) ([]string, error)
- func (db *DB) UpdateOptions(opts define.DBOptions) error
- type DBError
- type GenerateOptions
- type PageInfo
- type QueryResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain represents the base chain structure
func (*Chain) BatchInsert ¶ added in v4.1.3
BatchInsert performs batch insert operation with the given batch size
func (*Chain) BatchValues ¶
BatchValues sets batch insert values
func (*Chain) CreateTable ¶
CreateTable creates a table based on the model struct
func (*Chain) First ¶
func (c *Chain) First(dest ...interface{}) *QueryResult
First returns the first result
func (*Chain) IsInTransaction ¶
IsInTransaction returns whether the chain is currently in a transaction
func (*Chain) List ¶
func (c *Chain) List(dest ...interface{}) *QueryResult
List executes a SELECT query and returns all results
func (*Chain) NewCondition ¶ added in v4.1.3
NewCondition creates a new condition with AND join type
func (*Chain) NotBetween ¶ added in v4.1.3
NotBetween adds a NOT BETWEEN condition
func (*Chain) One ¶
func (c *Chain) One(dest ...interface{}) *QueryResult
One returns exactly one result
func (*Chain) OrIsNotNull ¶ added in v4.1.3
OrIsNotNull adds an OR IS NOT NULL condition
func (*Chain) OrNotBetween ¶ added in v4.1.3
OrNotBetween adds an OR NOT BETWEEN condition
func (*Chain) OrWhereGroup ¶ added in v4.1.3
OrWhereGroup starts a new condition group with OR join type
func (*Chain) OrderByDesc ¶
OrderByDesc adds a descending order by clause
func (*Chain) PageInfo ¶ added in v4.1.3
PageInfo executes a paginated query and returns pagination information
func (*Chain) RawExecute ¶
RawExecute executes a raw SQL query
func (*Chain) RawQuery ¶
func (c *Chain) RawQuery(sqlStr string, args ...interface{}) *QueryResult
RawQuery executes a raw SQL query
func (*Chain) ReleaseSavepoint ¶
ReleaseSavepoint releases the specified savepoint
func (*Chain) RollbackTo ¶
RollbackTo rolls back to the specified savepoint
func (*Chain) SetIsolationLevel ¶
func (c *Chain) SetIsolationLevel(level sql.IsolationLevel) *Chain
SetIsolationLevel sets the isolation level for the next transaction
func (*Chain) Transaction ¶
Transaction executes the given function within a transaction
func (*Chain) WhereGroup ¶ added in v4.1.3
WhereGroup starts a new condition group with AND join type
type DB ¶
type DB struct {
sync.RWMutex
DB *sql.DB
Factory define.SQLFactory
RoutineID int64
// contains filtered or unexported fields
}
DB represents the database connection
func OpenWithDefaults ¶ added in v4.1.4
OpenWithDefaults creates a new DB connection with default options
func (*DB) GenerateStruct ¶
GenerateStruct 生成单个表的结构体代码
func (*DB) GenerateStructs ¶
func (db *DB) GenerateStructs(opts GenerateOptions) error
GenerateStructs 批量生成表的结构体代码
func (*DB) GetOptions ¶ added in v4.1.4
GetOptions returns the current database options
func (*DB) GetTableInfo ¶
GetTableInfo 获取表信息
func (*DB) GetTableName ¶ added in v4.1.3
GetTableName returns the table name for a model
type GenerateOptions ¶
type GenerateOptions struct {
OutputDir string // 输出目录
PackageName string // 包名
Pattern string // 表名匹配模式
}
GenerateOptions 代码生成选项
type PageInfo ¶ added in v4.1.3
type PageInfo struct {
PageNum int `json:"pageNum"` // 当前页码
PageSize int `json:"pageSize"` // 每页大小
Total int64 `json:"total"` // 总记录数
Pages int `json:"pages"` // 总页数
HasPrev bool `json:"hasPrev"` // 是否有上一页
HasNext bool `json:"hasNext"` // 是否有下一页
List interface{} `json:"list"` // 当前页数据
IsFirstPage bool `json:"isFirstPage"` // 是否是第一页
IsLastPage bool `json:"isLastPage"` // 是否是最后页
}
PageInfo represents pagination information
type QueryResult ¶
type QueryResult struct {
Data []map[string]any `json:"data"`
Columns []string `json:"columns"`
// contains filtered or unexported fields
}
QueryResult represents a query result
func (*QueryResult) Empty ¶
func (qr *QueryResult) Empty() bool
Empty returns true if the result is empty
func (*QueryResult) First ¶
func (qr *QueryResult) First() *QueryResult
First returns the first result or error if no results
func (*QueryResult) Into ¶
func (qr *QueryResult) Into(dest interface{}) error
Into scans the result into a slice of structs
func (*QueryResult) Size ¶
func (qr *QueryResult) Size() int
Size returns the number of rows in the result