Documentation
¶
Index ¶
- func RegisterTenant(key string, valueFunc func(context.Context) string)
- type Tenant
- type Where
- type WhereOption
- type WhereOptions
- func (whr *WhereOptions) C(conds ...clause.Expression) *WhereOptions
- func (whr *WhereOptions) F(kvs ...any) *WhereOptions
- func (whr *WhereOptions) L(limit int) *WhereOptions
- func (whr *WhereOptions) O(offset int) *WhereOptions
- func (whr *WhereOptions) P(page int, pageSize int) *WhereOptions
- func (whr *WhereOptions) String() string
- func (whr *WhereOptions) T(ctx context.Context) *WhereOptions
- func (whr *WhereOptions) Where(db *gorm.DB) *gorm.DB
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Tenant ¶
type Tenant struct { Key string // The key associated with the tenant ValueFunc func(ctx context.Context) string // Function to retrieve the tenant's value based on the context }
Tenant represents a tenant with a key and a function to retrieve its value.
type WhereOption ¶
type WhereOption func(*WhereOptions)
WhereOption defines a function type that modifies WhereOptions.
func WithClauses ¶
func WithClauses(conds ...clause.Expression) WhereOption
WithClauses appends clauses to the Clauses field in WhereOptions.
func WithFilter ¶
func WithFilter(filter map[any]any) WhereOption
WithFilter initializes the Filters field in WhereOptions with the given filter criteria.
func WithLimit ¶
func WithLimit(limit int64) WhereOption
WithLimit initializes the Limit field in WhereOptions with the given limit value.
func WithOffset ¶
func WithOffset(offset int64) WhereOption
WithOffset initializes the Offset field in WhereOptions with the given offset value.
func WithPage ¶
func WithPage(page int, pageSize int) WhereOption
WithPage is a sugar function to convert page and pageSize into limit and offset in WhereOptions. This function is commonly used in business logic to facilitate pagination.
type WhereOptions ¶
type WhereOptions 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"` // 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 }
WhereOptions holds the options for GORM's Where query conditions.
func C ¶
func C(conds ...clause.Expression) *WhereOptions
C is a convenience function to create a new WhereOptions with conditions.
func F ¶
func F(kvs ...any) *WhereOptions
F is a convenience function to create a new WhereOptions with filters.
func L ¶
func L(limit int) *WhereOptions
L is a convenience function to create a new WhereOptions with limit.
func NewWhere ¶
func NewWhere(opts ...WhereOption) *WhereOptions
NewWhere constructs a new WhereOptions object, applying the given where options.
func O ¶
func O(offset int) *WhereOptions
O is a convenience function to create a new WhereOptions with offset.
func P ¶
func P(page int, pageSize int) *WhereOptions
P is a convenience function to create a new WhereOptions with page number and page size.
func T ¶
func T(ctx context.Context) *WhereOptions
T is a convenience function to create a new WhereOptions with tenant.
func (*WhereOptions) C ¶
func (whr *WhereOptions) C(conds ...clause.Expression) *WhereOptions
C adds conditions to the query.
func (*WhereOptions) F ¶
func (whr *WhereOptions) F(kvs ...any) *WhereOptions
F adds filters to the query.
func (*WhereOptions) L ¶
func (whr *WhereOptions) L(limit int) *WhereOptions
L sets the limit for the query.
func (*WhereOptions) O ¶
func (whr *WhereOptions) O(offset int) *WhereOptions
O sets the offset for the query.
func (*WhereOptions) P ¶
func (whr *WhereOptions) P(page int, pageSize int) *WhereOptions
P sets the pagination based on the page number and page size.
func (*WhereOptions) String ¶
func (whr *WhereOptions) String() string
String returns a JSON representation of the WhereOptions.
func (*WhereOptions) T ¶
func (whr *WhereOptions) T(ctx context.Context) *WhereOptions
T retrieves the value associated with the registered tenant using the provided context.