query

package
v0.7.14 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregationGroup

type AggregationGroup struct {
	Label string
	Logic model.FacetLogic
	Items AggregationItems
}

type AggregationItem

type AggregationItem struct {
	Label      string
	Count      uint
	IsEstimate bool
}

type AggregationItems

type AggregationItems = map[string]AggregationItem

type Aggregations

type Aggregations = maps.StringMap[AggregationGroup]

type AndCriteria

type AndCriteria struct {
	Criteria []Criteria
}

func (AndCriteria) Raw

func (c AndCriteria) Raw(ctx DbContext) (RawCriteria, error)

type BaseSubQuery

type BaseSubQuery interface {
	Count() (int64, error)
	TableName() string
	UnderlyingDB() *gorm.DB
}

type Callback

type Callback func(ctx context.Context, cbCtx CallbackContext, results any) error

type CallbackContext

type CallbackContext interface {
	DbContext
	Lock()
	Unlock()
}

type Criteria

type Criteria interface {
	Raw(c DbContext) (RawCriteria, error)
}

func And

func And(criteria ...Criteria) Criteria

func Not

func Not(criteria ...Criteria) Criteria

func Or

func Or(criteria ...Criteria) Criteria

func QueryStringCriteria

func QueryStringCriteria(str string) Criteria

type DaoCriteria

type DaoCriteria struct {
	Conditions func(ctx DbContext) ([]field.Expr, error)
	Joins      maps.InsertMap[string, struct{}]
}

func (DaoCriteria) Raw

func (c DaoCriteria) Raw(ctx DbContext) (RawCriteria, error)

type DbContext

type DbContext interface {
	Query() *dao.Query
	TableName() string
	NewSubQuery(context.Context) SubQuery
}

type DbCriteria

type DbCriteria struct {
	Sql  string
	Args []interface{}
}

func (DbCriteria) Raw

func (c DbCriteria) Raw(ctx DbContext) (RawCriteria, error)

type Facet

type Facet interface {
	FacetConfig
	Values(ctx FacetContext) (map[string]string, error)
	Criteria(filter FacetFilter) []Criteria
}

type FacetConfig

type FacetConfig interface {
	Key() string
	Label() string
	Logic() model.FacetLogic
	Filter() FacetFilter
	IsAggregated() bool
	AggregationOption(b OptionBuilder) (OptionBuilder, error)
}

func NewFacetConfig

func NewFacetConfig(options ...FacetOption) FacetConfig

type FacetContext

type FacetContext interface {
	DbContext
	Context() context.Context
	NewAggregationQuery(options ...Option) (SubQuery, error)
}

type FacetFilter

type FacetFilter map[string]struct{}

func (FacetFilter) HasKey added in v0.6.0

func (f FacetFilter) HasKey(key string) bool

func (FacetFilter) Values

func (f FacetFilter) Values() []string

Values allows iteration over deterministically sorted filter values, which helps with query caching.

type FacetOption

type FacetOption func(facetConfig) facetConfig

func FacetHasAggregationOption

func FacetHasAggregationOption(options ...Option) FacetOption

func FacetHasFilter

func FacetHasFilter(filter FacetFilter) FacetOption

func FacetHasKey

func FacetHasKey(key string) FacetOption

func FacetHasLabel

func FacetHasLabel(label string) FacetOption

func FacetIsAggregated

func FacetIsAggregated() FacetOption

func FacetUsesAndLogic

func FacetUsesAndLogic() FacetOption

func FacetUsesLogic

func FacetUsesLogic(logic model.FacetLogic) FacetOption

func FacetUsesOrLogic

func FacetUsesOrLogic() FacetOption

type GenCriteria

type GenCriteria func(ctx DbContext) (Criteria, error)

func (GenCriteria) Raw

func (c GenCriteria) Raw(ctx DbContext) (RawCriteria, error)

type GenericResult

type GenericResult[T interface{}] struct {
	TotalCount           uint
	TotalCountIsEstimate bool
	HasNextPage          bool
	Items                []T
	Aggregations         Aggregations
}

func GenericQuery

func GenericQuery[T interface{}](
	ctx context.Context,
	daoQ *dao.Query,
	option Option,
	tableName string,
	factory SubQueryFactory,
) (r GenericResult[T], _ error)

type GenericSubQuery

type GenericSubQuery[T BaseSubQuery] struct {
	SubQuery BaseSubQuery
}

func (GenericSubQuery[T]) Count

func (sq GenericSubQuery[T]) Count() (int64, error)

func (GenericSubQuery[T]) Scopes

func (sq GenericSubQuery[T]) Scopes(fns ...func(gen.Dao) gen.Dao) SubQuery

func (GenericSubQuery[T]) TableName

func (sq GenericSubQuery[T]) TableName() string

func (GenericSubQuery[T]) UnderlyingDB

func (sq GenericSubQuery[T]) UnderlyingDB() *gorm.DB

type GormScope

type GormScope = func(gen.Dao) gen.Dao

type HasManyHydrator

type HasManyHydrator[Root any, RootID comparable, JoinSub any, Sub any] interface {
	RootID(root Root) (RootID, bool)
	GetJoinSubs(ctx context.Context, dbCtx DbContext, ids []RootID) ([]JoinSub, error)
	JoinSubToRootIDAndSub(j JoinSub) (RootID, Sub)
	Hydrate(root *Root, subs []Sub)
}

type HasOneHydrator

type HasOneHydrator[Root any, Sub any, SubID comparable] interface {
	RootToSubID(root Root) (SubID, bool)
	GetSubs(ctx context.Context, dbCtx DbContext, ids []SubID) ([]Sub, error)
	SubID(sub Sub) SubID
	Hydrate(root *Root, sub Sub)
	MustSucceed() bool
}

type NotCriteria

type NotCriteria struct {
	Criteria []Criteria
}

func (NotCriteria) Raw

func (c NotCriteria) Raw(ctx DbContext) (RawCriteria, error)

type Option

type Option = func(ctx OptionBuilder) (OptionBuilder, error)

func CacheMode

func CacheMode(mode cache.Mode) Option

func CacheWarm

func CacheWarm() Option

func Cached

func Cached() Option

func Context

func Context(fn func(ctx context.Context) context.Context) Option

func DefaultOption

func DefaultOption() Option

func Group added in v0.3.0

func Group(columns ...clause.Column) Option

func HydrateHasMany

func HydrateHasMany[Root any, RootID comparable, JoinSub any, Sub any](h HasManyHydrator[Root, RootID, JoinSub, Sub]) Option

func HydrateHasOne

func HydrateHasOne[Root any, Sub any, SubID comparable](h HasOneHydrator[Root, Sub, SubID]) Option

func Join

func Join(fn func(*dao.Query) []TableJoin) Option

func Limit

func Limit(n uint) Option

func Offset

func Offset(n uint) Option

func Options

func Options(o ...Option) Option

func OrderBy

func OrderBy(columns ...clause.OrderByColumn) Option

func OrderByColumn

func OrderByColumn(field string, desc bool) Option

func OrderByQueryStringRank

func OrderByQueryStringRank() Option

func Preload

func Preload(fn func(query *dao.Query) []field.RelationField) Option

func QueryString

func QueryString(str string) Option

func RequireJoin

func RequireJoin(names ...string) Option

func Select added in v0.3.0

func Select(columns ...clause.Expr) Option

func SelectAll added in v0.3.0

func SelectAll() Option

func Table

func Table(name string) Option

func Where

func Where(conditions ...Criteria) Option

func WithAggregationBudget added in v0.6.0

func WithAggregationBudget(budget float64) Option

func WithFacet

func WithFacet(facets ...Facet) Option

func WithHasNextPage added in v0.4.0

func WithHasNextPage(bl bool) Option

func WithTotalCount

func WithTotalCount(bl bool) Option

type OptionBuilder

type OptionBuilder interface {
	DbContext
	Table(string) OptionBuilder
	Join(...TableJoin) OptionBuilder
	RequireJoin(...string) OptionBuilder
	Scope(...Scope) OptionBuilder
	Select(...clause.Expr) OptionBuilder
	OrderBy(...clause.OrderByColumn) OptionBuilder
	Limit(uint) OptionBuilder
	Offset(uint) OptionBuilder
	Group(...clause.Column) OptionBuilder
	Facet(...Facet) OptionBuilder
	Preload(...field.RelationField) OptionBuilder
	Callback(...Callback) OptionBuilder
	Context(func(ctx context.Context) context.Context) OptionBuilder

	WithTotalCount(bool) OptionBuilder
	WithHasNextPage(bool) OptionBuilder
	WithAggregationBudget(float64) OptionBuilder
	AggregationBudget() float64
	// contains filtered or unexported methods
}

type OrCriteria

type OrCriteria struct {
	Criteria []Criteria
}

func (OrCriteria) Raw

func (c OrCriteria) Raw(ctx DbContext) (RawCriteria, error)

type RawCriteria

type RawCriteria struct {
	Query interface{}
	Args  []interface{}
	Joins maps.InsertMap[string, struct{}]
}

func (RawCriteria) Raw

func (c RawCriteria) Raw(ctx DbContext) (RawCriteria, error)

type RawJoin

type RawJoin struct {
	Query string
	Args  []interface{}
}

type ResultItem

type ResultItem struct {
	QueryStringRank float64
}

type Scope

type Scope = func(SubQuery) error

type SearchParams

type SearchParams struct {
	QueryString       model.NullString
	Limit             model.NullUint
	Offset            model.NullUint
	TotalCount        model.NullBool
	HasNextPage       model.NullBool
	Cached            model.NullBool
	AggregationBudget model.NullFloat64
}

func (SearchParams) Option

func (s SearchParams) Option() Option

type SubQuery

type SubQuery interface {
	BaseSubQuery
	Scopes(...GormScope) SubQuery
}

type SubQueryFactory

type SubQueryFactory = func(context.Context, *dao.Query) SubQuery

type TableJoin

type TableJoin struct {
	Table        schema.Tabler
	On           []field.Expr
	Type         TableJoinType
	Dependencies maps.InsertMap[string, struct{}]
	Required     bool
}

type TableJoinType

type TableJoinType int
const (
	TableJoinTypeInner TableJoinType = iota
	TableJoinTypeLeft
	TableJoinTypeRight
)

Jump to

Keyboard shortcuts

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