Documentation
¶
Index ¶
- func RegisterTenant(key string, valueFunc func(context.Context) string)
- type Option
- func WithClauses(conds ...clause.Expression) Option
- func WithFilter(filter map[any]any) Option
- func WithLimit(limit int64) Option
- func WithOffset(offset int64) Option
- func WithOrder(order string) Option
- func WithPage(page int, pageSize int) Option
- func WithQuery(query interface{}, args ...interface{}) Option
- type Options
- func C(conds ...clause.Expression) *Options
- func F(kvs ...any) *Options
- func L(limit int) *Options
- func NewWhere(opts ...Option) *Options
- func O(offset int) *Options
- func P(page int, pageSize int) *Options
- func Q(query interface{}, args ...interface{}) *Options
- func R(order string) *Options
- func T(ctx context.Context) *Options
- func (whr *Options) C(conds ...clause.Expression) *Options
- func (whr *Options) F(kvs ...any) *Options
- func (whr *Options) L(limit int) *Options
- func (whr *Options) O(offset int) *Options
- func (whr *Options) P(page int, pageSize int) *Options
- func (whr *Options) Q(query interface{}, args ...interface{}) *Options
- func (whr *Options) R(order string) *Options
- func (whr *Options) T(ctx context.Context) *Options
- func (whr *Options) Where(db *gorm.DB) *gorm.DB
- type Query
- type Tenant
- type Where
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*Options)
Option defines a function type that modifies Options.
func WithClauses ¶
func WithClauses(conds ...clause.Expression) Option
WithClauses appends clauses to the Clauses field in Options.
func WithFilter ¶
WithFilter initializes the Filters field in Options with the given filter criteria.
func WithOffset ¶
WithOffset initializes the Offset field in Options with the given offset value.
func WithPage ¶
WithPage is a sugar function to convert page and pageSize into limit and offset in Options. This function is commonly used in business logic to facilitate pagination.
func WithQuery ¶
func WithQuery(query interface{}, args ...interface{}) Option
WithQuery creates an Option that adds a query condition with arguments to the Options struct. The query parameter can be a string, map, struct, or any other type supported by GORM's Where clause. The args parameter contains values that will replace placeholders in the query string.
type Options ¶
type Options struct {
// Offset defines the starting point for pagination.
// +optional
Offset int `json:"offset"`
// Limit defines the maximum number of results to return.
// +optional
Limit int `json:"limit"`
// Order defines the order for list.
// +optional
Order string `json:"order"`
// Filters contains key-value pairs for filtering records.
Filters map[any]any
// Clauses contains custom clauses to be appended to the query.
Clauses []clause.Expression
// Queries contains a list of queries to be executed.
Queries []Query
}
Options holds the options for GORM's Where query conditions.
func C ¶
func C(conds ...clause.Expression) *Options
C is a convenience function to create a new Options with conditions.
func Q ¶
func Q(query interface{}, args ...interface{}) *Options
Q is a convenience function to create a new Options with Queries.
func (*Options) C ¶
func (whr *Options) C(conds ...clause.Expression) *Options
C adds conditions to the query.
func (*Options) Q ¶
Q adds a query condition with arguments to the Options struct and returns the modified Options. This method appends a new Query instance to the Queries slice.
type Query ¶
type Query struct {
// Query holds the condition to be used in the GORM query.
// Can be a string, map, struct, or other types supported by GORM's Where clause.
Query interface{}
// Args holds the arguments that will be passed to the query condition.
// These values will be used to replace placeholders in the query.
Args []interface{}
}
Query represents a database query with its arguments. It contains the query condition and any associated parameters.