query

package
v0.0.0-...-513868c Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: Apache-2.0 Imports: 4 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PredicateContains   = &Predicate{keywords: []string{"Contains"}, numArgs: 1}
	PredicateStartsWith = &Predicate{keywords: []string{"StartsWith"}, numArgs: 1}
	PredicateEndsWith   = &Predicate{keywords: []string{"EndsWith"}, numArgs: 1}
	PredicateIsNull     = &Predicate{keywords: []string{"IsNull"}, numArgs: 0}
	PredicateIsNotNull  = &Predicate{keywords: []string{"IsNotNull"}, numArgs: 0}
	//PredicateIsEmpty is collection empty,
	//If you want to express that the string is not empty, you can use 'Is',
	//and then use an empty string as a parameter, the same below
	PredicateIsEmpty = &Predicate{keywords: []string{"IsEmpty"}, numArgs: 0}
	//PredicateIsNotEmpty is collection not empty
	PredicateIsNotEmpty = &Predicate{keywords: []string{"IsNotEmpty"}, numArgs: 0}
	PredicateIsFalse    = &Predicate{keywords: []string{"IsFalse"}, numArgs: 0}
	PredicateIsTrue     = &Predicate{keywords: []string{"IsTrue"}, numArgs: 0}
	PredicateMatches    = &Predicate{keywords: []string{"Matches"}, numArgs: 1}
	//PredicateBetween The BETWEEN operator is inclusive: begin and end values are included.
	PredicateBetween = &Predicate{keywords: []string{"Between"}, numArgs: 2}
	PredicateNotIn   = &Predicate{keywords: []string{"NotIn"}, numArgs: 1}
	PredicateIn      = &Predicate{keywords: []string{"In"}, numArgs: 1}
	PredicateGT      = &Predicate{keywords: []string{"GT"}, numArgs: 1}
	PredicateLT      = &Predicate{keywords: []string{"LT"}, numArgs: 1}
	PredicateGTE     = &Predicate{keywords: []string{"GTE"}, numArgs: 1}
	PredicateLTE     = &Predicate{keywords: []string{"LTE"}, numArgs: 1}
	PredicateIsNot   = &Predicate{keywords: []string{"IsNot", "NotEquals", "NE"}, numArgs: 1}
	PredicateIs      = &Predicate{keywords: []string{"Equals", "Is", "EQ", ""}, numArgs: 1}
)
View Source
var (
	FilterModifierIgnoreCase    = &FilterModifier{keywords: []string{"IgnoreCase", "IC"}, global: false}
	FilterModifierAllIgnoreCase = &FilterModifier{keywords: []string{"AllIgnoreCase", "AllIC"}, global: true}
)
View Source
var (
	SubjectFind   = &Subject{keywords: []string{"Find", "Query", "Get", "Search"}, sortable: true}
	SubjectCount  = &Subject{keywords: []string{"Count"}, sortable: false}
	SubjectExists = &Subject{keywords: []string{"Exists"}, sortable: false}
	SubjectDelete = &Subject{keywords: []string{"Delete", "Remove"}, sortable: true}
)
View Source
var (
	SubjectModifierDistinct = &SubjectModifier{
		keywords: []string{"Distinct"},
		subjects: map[*Subject]bool{SubjectFind: true, SubjectCount: true},
	}
	SubjectModifierTop = &SubjectModifier{
		keywords: []string{"Top"},
		subjects: map[*Subject]bool{SubjectFind: true, SubjectDelete: true},
	}
)

Functions

This section is empty.

Types

type Direction

type Direction string
const (
	DirectionDesc Direction = "Desc"
	DirectionAsc  Direction = "Asc"
)

func (Direction) String

func (d Direction) String() string

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

func NewFilter

func NewFilter(fieldName string, predicate *Predicate, opts ...FilterOption) *Filter

func (*Filter) FieldName

func (f *Filter) FieldName() string

func (*Filter) FillValue

func (f *Filter) FillValue(values []any) error

func (*Filter) FilterModifier

func (f *Filter) FilterModifier() *FilterModifier

func (*Filter) NamedArgs

func (f *Filter) NamedArgs() []string

func (*Filter) NumValue

func (f *Filter) NumValue() (num int)

func (*Filter) Predicate

func (f *Filter) Predicate() *Predicate

func (Filter) String

func (f Filter) String() string

func (*Filter) Values

func (f *Filter) Values() []any

type FilterGroup

type FilterGroup struct {
	// contains filtered or unexported fields
}

func NewFilterGroup

func NewFilterGroup(groups []*FilterGroup, logicOperator LogicOperator) *FilterGroup

func NewFilterGroupWithFilters

func NewFilterGroupWithFilters(filters []*Filter, logicOperator LogicOperator) *FilterGroup

func (*FilterGroup) FillNamedArgs

func (fg *FilterGroup) FillNamedArgs(namedArgs []string) error

func (*FilterGroup) FillValues

func (fg *FilterGroup) FillValues(values []any) error

func (*FilterGroup) IsEmpty

func (fg *FilterGroup) IsEmpty() bool

func (*FilterGroup) NumValue

func (fg *FilterGroup) NumValue() (num int)

func (FilterGroup) String

func (fg FilterGroup) String() string

type FilterModifier

type FilterModifier struct {
	// contains filtered or unexported fields
}

func (*FilterModifier) Global

func (p *FilterModifier) Global() bool

func (*FilterModifier) Keywords

func (p *FilterModifier) Keywords() []string

func (FilterModifier) String

func (p FilterModifier) String() string

type FilterOption

type FilterOption func(filter *Filter)

func WithFilterModifier

func WithFilterModifier(modifier *FilterModifier) FilterOption

func WithFilterNamedArgs

func WithFilterNamedArgs(namedArgs ...string) FilterOption

func WithFilterValues

func WithFilterValues(values ...any) FilterOption

type LogicOperator

type LogicOperator string
const (
	LogicOperatorAnd LogicOperator = "And"
	LogicOperatorOr  LogicOperator = "Or"
)

func (LogicOperator) String

func (l LogicOperator) String() string

type Option

type Option func(q *Query)

func WithFilterGroup

func WithFilterGroup(filterGroup *FilterGroup) Option

func WithPager

func WithPager(pager Pager) Option

func WithSorts

func WithSorts(sorts []*Sort) Option

func WithSubjectModifier

func WithSubjectModifier(modifier *SubjectModifier) Option

func WithSubjectModifierArgs

func WithSubjectModifierArgs(subjectModifierArgs map[SubjectModifierArg]any) Option

func WithTable

func WithTable(table Table) Option

type PageRequest

type PageRequest struct {
	// contains filtered or unexported fields
}

func NewPageRequest

func NewPageRequest(page int, pageSize int, searchCount bool) *PageRequest

func (*PageRequest) Offset

func (p *PageRequest) Offset() int

func (*PageRequest) Page

func (p *PageRequest) Page() int

func (*PageRequest) PageSize

func (p *PageRequest) PageSize() int

func (*PageRequest) SearchCount

func (p *PageRequest) SearchCount() bool

func (*PageRequest) SetPage

func (p *PageRequest) SetPage(page int)

func (*PageRequest) SetPageSize

func (p *PageRequest) SetPageSize(pageSize int)

func (*PageRequest) SetSearchCount

func (p *PageRequest) SetSearchCount(searchCount bool)

func (PageRequest) String

func (p PageRequest) String() string

type Pager

type Pager interface {
	Page() int
	PageSize() int
	Offset() int
	SearchCount() bool
	String() string
}

type Predicate

type Predicate struct {
	// contains filtered or unexported fields
}

func (*Predicate) Keywords

func (p *Predicate) Keywords() []string

func (*Predicate) NumArgs

func (p *Predicate) NumArgs() int

func (Predicate) String

func (p Predicate) String() string

type Query

type Query struct {
	// contains filtered or unexported fields
}

func New

func New(subject *Subject, opts ...Option) *Query

func (*Query) FilterGroup

func (q *Query) FilterGroup() *FilterGroup

func (*Query) Pager

func (q *Query) Pager() Pager

func (*Query) Sorts

func (q *Query) Sorts() []*Sort

func (Query) String

func (q Query) String() string

func (*Query) Subject

func (q *Query) Subject() *Subject

func (*Query) SubjectModifier

func (q *Query) SubjectModifier() *SubjectModifier

func (*Query) SubjectModifierArgs

func (q *Query) SubjectModifierArgs() map[SubjectModifierArg]any

func (*Query) Table

func (q *Query) Table() Table

func (*Query) With

func (q *Query) With(opts ...Option) *Query

type RDBTranslator

type RDBTranslator struct {
	// contains filtered or unexported fields
}

func NewRDBTranslator

func NewRDBTranslator(engin engine.Engine) *RDBTranslator

func (*RDBTranslator) Translate

func (t *RDBTranslator) Translate(ctx context.Context, query *Query) (result string, err error)

func (*RDBTranslator) TranslateCount

func (t *RDBTranslator) TranslateCount(ctx context.Context, query *Query) (result string, err error)

func (*RDBTranslator) TranslateDelete

func (t *RDBTranslator) TranslateDelete(ctx context.Context, query *Query) (result string, err error)

func (*RDBTranslator) TranslateExists

func (t *RDBTranslator) TranslateExists(ctx context.Context, query *Query) (result string, err error)

func (*RDBTranslator) TranslateFilter

func (t *RDBTranslator) TranslateFilter(ctx context.Context, f *Filter) (result string, err error)

func (*RDBTranslator) TranslateFilterGroup

func (t *RDBTranslator) TranslateFilterGroup(ctx context.Context, fg *FilterGroup) (result string, err error)

func (*RDBTranslator) TranslateFind

func (t *RDBTranslator) TranslateFind(ctx context.Context, query *Query) (result string, err error)

func (*RDBTranslator) TranslateLogicOperator

func (t *RDBTranslator) TranslateLogicOperator(ctx context.Context, operator LogicOperator) (result string, err error)

func (*RDBTranslator) TranslatePager

func (t *RDBTranslator) TranslatePager(ctx context.Context, pager Pager) (result string, err error)

func (*RDBTranslator) TranslateSort

func (t *RDBTranslator) TranslateSort(ctx context.Context, sort *Sort) (result string, err error)

func (*RDBTranslator) TranslateSorts

func (t *RDBTranslator) TranslateSorts(ctx context.Context, sorts []*Sort) (result string, err error)

func (*RDBTranslator) TranslateTable

func (t *RDBTranslator) TranslateTable(ctx context.Context, table Table) (string, error)

type Sort

type Sort struct {
	// contains filtered or unexported fields
}

func NewSort

func NewSort(fieldName string, direction Direction) *Sort

func (*Sort) Direction

func (s *Sort) Direction() Direction

func (*Sort) FieldName

func (s *Sort) FieldName() string

func (Sort) String

func (s Sort) String() string

type Subject

type Subject struct {
	// contains filtered or unexported fields
}

func (*Subject) Keywords

func (s *Subject) Keywords() []string

func (*Subject) Name

func (s *Subject) Name() string

func (*Subject) Sortable

func (s *Subject) Sortable() bool

func (Subject) String

func (s Subject) String() string

type SubjectModifier

type SubjectModifier struct {
	// contains filtered or unexported fields
}

func (*SubjectModifier) Keywords

func (s *SubjectModifier) Keywords() []string

func (SubjectModifier) String

func (s SubjectModifier) String() string

func (*SubjectModifier) Subjects

func (s *SubjectModifier) Subjects() map[*Subject]bool

type SubjectModifierArg

type SubjectModifierArg string

type Table

type Table interface {
	Schema() string
	Name() string
}

func NewTable

func NewTable(name string, opts ...TableOption) Table

type TableOption

type TableOption func(table *simpleTable)

func WithTableSchema

func WithTableSchema(schema string) TableOption

type Translator

type Translator interface {
	Translate(ctx context.Context, query *Query) (string, error)
	TranslateFind(ctx context.Context, query *Query) (string, error)
	TranslateCount(ctx context.Context, query *Query) (string, error)
	TranslateExists(ctx context.Context, query *Query) (string, error)
	TranslateDelete(ctx context.Context, query *Query) (string, error)
	TranslateTable(ctx context.Context, table Table) (string, error)
	TranslateFilterGroup(ctx context.Context, group *FilterGroup) (string, error)
	TranslateFilter(ctx context.Context, filter *Filter) (string, error)
	TranslateLogicOperator(ctx context.Context, operator LogicOperator) (string, error)
	TranslateSorts(ctx context.Context, sorts []*Sort) (string, error)
	TranslateSort(ctx context.Context, sort *Sort) (string, error)
	TranslatePager(ctx context.Context, pager Pager) (string, error)
}

Jump to

Keyboard shortcuts

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