where

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 License: MIT Imports: 3 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 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

func WithFilter(filter map[any]any) Option

WithFilter initializes the Filters field in Options with the given filter criteria.

func WithLimit

func WithLimit(limit int64) Option

WithLimit initializes the Limit field in Options with the given limit value.

func WithOffset

func WithOffset(offset int64) Option

WithOffset initializes the Offset field in Options with the given offset value.

func WithOrder

func WithOrder(order string) Option

WithLimit initializes the Limit field in Options with the given limit value.

func WithPage

func WithPage(page int, pageSize int) Option

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 F

func F(kvs ...any) *Options

F is a convenience function to create a new Options with filters.

func L

func L(limit int) *Options

L is a convenience function to create a new Options with limit.

func NewWhere

func NewWhere(opts ...Option) *Options

NewWhere constructs a new Options object, applying the given where options.

func O

func O(offset int) *Options

O is a convenience function to create a new Options with offset.

func P

func P(page int, pageSize int) *Options

P is a convenience function to create a new Options with page number and page size.

func Q

func Q(query interface{}, args ...interface{}) *Options

Q is a convenience function to create a new Options with Queries.

func R

func R(order string) *Options

R is a convenience function to create a new Options with order.

func T

func T(ctx context.Context) *Options

T is a convenience function to create a new Options with tenant.

func (*Options) C

func (whr *Options) C(conds ...clause.Expression) *Options

C adds conditions to the query.

func (*Options) F

func (whr *Options) F(kvs ...any) *Options

F adds filters to the query.

func (*Options) L

func (whr *Options) L(limit int) *Options

L sets the limit for the query.

func (*Options) O

func (whr *Options) O(offset int) *Options

O sets the offset for the query.

func (*Options) P

func (whr *Options) P(page int, pageSize int) *Options

P sets the pagination based on the page number and page size.

func (*Options) Q

func (whr *Options) Q(query interface{}, args ...interface{}) *Options

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.

func (*Options) R

func (whr *Options) R(order string) *Options

R sets the order for the query.

func (*Options) T

func (whr *Options) T(ctx context.Context) *Options

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

func (*Options) Where

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

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

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.

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
}

Where defines an interface for types that can modify GORM database queries.

Jump to

Keyboard shortcuts

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