filter

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EOF    = 0
	COLON  = ':'
	COMMA  = ','
	AND    = COMMA
	OR     = '|'
	EQ     = '='
	LIKE   = '~'
	NOT    = '!'
	LT     = '<'
	GT     = '>'
	QUOTE  = '"'
	SQUOTE = '\''
	ESCAPE = '\\'
	SPACE  = ' '
	LPAREN = '('
	RPAREN = ')'
)
View Source
const (
	LITERAL  = 0x01
	STRING   = 0x02
	OPERATOR = 0x03
)
View Source
const (
	QueryParam = "filter"
)

Variables

This section is empty.

Functions

func AsValue

func AsValue(t Token) (object interface{})

AsValue returns the real value.

func Errorf

func Errorf(s string, v ...interface{}) (err error)

Errorf build error.

Types

type Assert

type Assert struct {
	Field string
	Kind  byte
	And   bool
}

Assert -

type Error

type Error struct {
	Reason string
}

Error reports bad request errors.

func (*Error) Error

func (r *Error) Error() string

func (*Error) Is

func (r *Error) Is(err error) (matched bool)

type Field

type Field struct {
	Predicate
}

Field predicate.

func (*Field) As

func (f *Field) As(s string) (named Field)

As returns the renamed field.

func (*Field) Expand

func (f *Field) Expand() (expanded []Field)

Expand flattens a multi-value field and returns a Field for each value.

func (*Field) Name

func (f *Field) Name() (s string)

Name returns the field name.

func (*Field) Resource

func (f *Field) Resource() (s string)

Resource returns the field resource.

func (*Field) SQL

func (f *Field) SQL() (s string, vList []interface{})

SQL builds SQL. Returns statement and values (for ?).

func (*Field) Where

func (f *Field) Where(in *gorm.DB) (out *gorm.DB)

Where updates the where clause.

type FieldSelector

type FieldSelector []string

FieldSelector fields. fields with '+' prefix are included. fields with '-' prefix are excluded. Fields scoped to a resource are excluded. An empty selector includes ALL.

func (FieldSelector) Match

func (r FieldSelector) Match(f *Field) (m bool)

Match fields by qualified name.

type Filter

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

Filter is a collection of predicates.

func New

func New(ctx *gin.Context, assertions []Assert) (f Filter, err error)

New filter.

func (*Filter) Delete

func (f *Filter) Delete(name string) (found bool)

Delete specified fields.

func (*Filter) Empty

func (f *Filter) Empty() bool

Empty returns true when the filter has no predicates.

func (*Filter) Field

func (f *Filter) Field(name string) (field Field, found bool)

Field returns a field.

func (*Filter) Fields

func (f *Filter) Fields(name string) (fields []Field)

Fields returns fields.

func (*Filter) Resource

func (f *Filter) Resource(r string) (filter Filter)

Resource returns a filter scoped to resource.

func (*Filter) Validate

func (f *Filter) Validate(assertions []Assert) (err error)

Validate -

func (*Filter) Where

func (f *Filter) Where(in *gorm.DB, selector ...string) (out *gorm.DB)

Where applies (root) fields to the where clause.

func (*Filter) With

func (f *Filter) With(selector ...string) (out Filter)

With return filter with selected predicates.

type Lexer

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

Lexer token reader.

func (*Lexer) With

func (r *Lexer) With(filter string) (err error)

With builds with the specified filter.

type List

type List struct {
	*Lexer
}

List construct. Example: (red|blue|green)

func (*List) Build

func (r *List) Build() (v Value, err error)

Build the value.

type Operator

type Operator struct {
	*Reader
}

Operator token reader.

func (*Operator) Read

func (q *Operator) Read() (token Token, err error)

Read token.

type Parser

type Parser struct {
}

Parser used to parse the filter.

func (*Parser) Filter

func (r *Parser) Filter(filter string) (f Filter, err error)

Filter parses the filter and builds a Filter.

type Predicate

type Predicate struct {
	Unused   Token
	Field    Token
	Operator Token
	Value    Value
}

Predicate filter predicate.

type Quoted

type Quoted struct {
	*Reader
}

Quoted string token reader.

func (*Quoted) Read

func (q *Quoted) Read() (token Token, err error)

Read token.

type Reader

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

Reader scan the input.

type Token

type Token struct {
	Kind  byte
	Value string
}

Token scanned token.

type Value

type Value []Token

Value term value.

func (Value) ByKind

func (r Value) ByKind(kind ...byte) (matched []Token)

ByKind returns values by kind.

func (*Value) Operator

func (r *Value) Operator(operator byte) (matched bool)

Operator returns true when contains the specified operator.

Jump to

Keyboard shortcuts

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