Documentation
¶
Index ¶
- Variables
- type Builder
- func (b *Builder) Build() (string, []interface{})
- func (b *Builder) From(table string) *Builder
- func (b *Builder) GroupBy(fields ...string) *Builder
- func (b *Builder) Having(condition string, args ...interface{}) *Builder
- func (b *Builder) Join(table, on string) *Builder
- func (b *Builder) LeftJoin(table, on string) *Builder
- func (b *Builder) Limit(limit int) *Builder
- func (b *Builder) Offset(offset int) *Builder
- func (b *Builder) OrderBy(field string) *Builder
- func (b *Builder) OrderByDesc(field string) *Builder
- func (b *Builder) Reset() *Builder
- func (b *Builder) RightJoin(table, on string) *Builder
- func (b *Builder) Select(fields ...string) *Builder
- func (b *Builder) String() string
- func (b *Builder) Where(condition string, args ...interface{}) *Builder
- func (b *Builder) WhereOr(condition string, args ...interface{}) *Builder
- type Manager
- func (m *Manager) ExecuteInTx(ctx context.Context, db defs.SQLDatabase, fn func(context.Context) error) error
- func (m *Manager) ExecuteInTxWithOpts(ctx context.Context, db defs.SQLDatabase, opts *defs.TxOptions, ...) error
- func (m *Manager) FromContext(ctx context.Context) (defs.Transaction, bool)
- func (m *Manager) IsInTx(ctx context.Context) bool
- func (m *Manager) MustFromContext(ctx context.Context) defs.Transaction
- func (m *Manager) WithContext(ctx context.Context, tx defs.Transaction) context.Context
- type Pager
- type PaginateResult
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTxNotFound is returned when transaction is not found in context ErrTxNotFound = errors.New("transaction not found in context") )
var TxManager = &Manager{}
TxManager is the global transaction manager
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a SQL query builder
func (*Builder) OrderByDesc ¶
OrderByDesc adds a DESC ORDER BY clause
type Manager ¶
type Manager struct{}
Manager manages database transactions
func (*Manager) ExecuteInTx ¶
func (m *Manager) ExecuteInTx(ctx context.Context, db defs.SQLDatabase, fn func(context.Context) error) error
ExecuteInTx executes a function within a transaction If the function returns an error, the transaction is rolled back Otherwise, the transaction is committed
func (*Manager) ExecuteInTxWithOpts ¶
func (m *Manager) ExecuteInTxWithOpts(ctx context.Context, db defs.SQLDatabase, opts *defs.TxOptions, fn func(context.Context) error) error
ExecuteInTxWithOpts executes a function within a transaction with options
func (*Manager) FromContext ¶
FromContext retrieves transaction from context
func (*Manager) MustFromContext ¶
func (m *Manager) MustFromContext(ctx context.Context) defs.Transaction
MustFromContext retrieves transaction from context or panics
func (*Manager) WithContext ¶
WithContext adds transaction to context
type Pager ¶
type Pager struct {
Page int `json:"page"` // Current page number (1-based)
PageSize int `json:"page_size"` // Number of items per page
Total int64 `json:"total"` // Total number of items
TotalPage int `json:"total_page"` // Total number of pages
}
Pager represents a pagination result
type PaginateResult ¶
type PaginateResult struct {
Items interface{} `json:"items"`
Pager *Pager `json:"pager"`
}
PaginateResult wraps a slice with pagination info
func NewPaginateResult ¶
func NewPaginateResult(items interface{}, pager *Pager) *PaginateResult
NewPaginateResult creates a new paginated result