where

package
v0.0.0-...-d35a86b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterTenant

func RegisterTenant(key string, valueFunc func(context.Context) string)

RegisterTenant registers a new tenant with the specified key and value function.

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 Where

type Where interface {
	Where(db *gorm.DB) *gorm.DB
}

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

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

T retrieves the value associated with the registered tenant using the provided context.

func (*WhereOptions) Where

func (whr *WhereOptions) Where(db *gorm.DB) *gorm.DB

Where applies the filters and clauses to the given gorm.DB instance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL