where

package
v0.2.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package where is used to handle GORM's Where query conditions.

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 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.

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"`
	// 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
}

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 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) 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 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
}

Jump to

Keyboard shortcuts

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