parser

package
v0.0.0-...-0ad5b3e Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package parser contains expression parser for search parameter.

Index

Constants

View Source
const DefaultArgsLen = 6

Variables

This section is empty.

Functions

This section is empty.

Types

type Boolean

type Boolean bool

func (*Boolean) Capture

func (b *Boolean) Capture(values []string) error

type Compare

type Compare struct {
	Operator string   `@( "<=" | ">=" | "=" | "<" | ">" | "!=" )`
	Operand  *Operand `(  @@`
	Select   *Operand ` | @@ )`
}

func (*Compare) ExprQuery

func (c *Compare) ExprQuery(op string) bson.M

func (*Compare) MongoQuery

func (c *Compare) MongoQuery() bson.M

func (*Compare) NotPostgresQuery

func (c *Compare) NotPostgresQuery() (string, pgx.NamedArgs)

func (*Compare) PostgresQuery

func (c *Compare) PostgresQuery() (string, pgx.NamedArgs)

type Condition

type Condition struct {
	Operand *ConditionOperand `  @@`
	Not     *Condition        `| "NOT" @@`
}

func (*Condition) GetFields

func (c *Condition) GetFields() []string

func (*Condition) MongoExprQuery

func (c *Condition) MongoExprQuery() bson.M

func (*Condition) MongoQuery

func (c *Condition) MongoQuery() bson.M

func (*Condition) PostgresQuery

func (c *Condition) PostgresQuery(prefix string) (string, pgx.NamedArgs)

type ConditionOperand

type ConditionOperand struct {
	Operand      *Operand      `@@`
	ConditionRHS *ConditionRHS `[ @@ ]`
}

func (*ConditionOperand) GetFields

func (o *ConditionOperand) GetFields() []string

func (*ConditionOperand) MongoExprQuery

func (o *ConditionOperand) MongoExprQuery() bson.M

func (*ConditionOperand) MongoQuery

func (o *ConditionOperand) MongoQuery() bson.M

func (*ConditionOperand) NotExprQuery

func (o *ConditionOperand) NotExprQuery() bson.M

func (*ConditionOperand) NotMongoQuery

func (o *ConditionOperand) NotMongoQuery() bson.M

func (*ConditionOperand) NotPostgresQuery

func (o *ConditionOperand) NotPostgresQuery(prefix string) (string, pgx.NamedArgs)

func (*ConditionOperand) PostgresQuery

func (o *ConditionOperand) PostgresQuery(prefix string) (string, pgx.NamedArgs)

type ConditionRHS

type ConditionRHS struct {
	Compare     *Compare     `  @@`
	Like        *Like        `| "LIKE" @@`
	NotLike     *NotLike     `| "NOT" "LIKE" @@`
	Contains    *Contains    `| "CONTAINS" @@`
	NotContains *NotContains `| "NOT" "CONTAINS" @@`
}

func (*ConditionRHS) ExprQuery

func (r *ConditionRHS) ExprQuery(op string) bson.M

func (*ConditionRHS) MongoQuery

func (r *ConditionRHS) MongoQuery() bson.M

func (*ConditionRHS) NotExprQuery

func (r *ConditionRHS) NotExprQuery(op string) bson.M

func (*ConditionRHS) NotMongoQuery

func (r *ConditionRHS) NotMongoQuery() bson.M

func (*ConditionRHS) NotPostgresQuery

func (r *ConditionRHS) NotPostgresQuery() (string, pgx.NamedArgs)

func (*ConditionRHS) PostgresQuery

func (r *ConditionRHS) PostgresQuery() (string, pgx.NamedArgs)

type Contains

type Contains struct {
	Operand *Operand `@@`
}

func (*Contains) ExprQuery

func (l *Contains) ExprQuery(op string) bson.M

func (*Contains) MongoQuery

func (l *Contains) MongoQuery() bson.M

func (*Contains) PostgresQuery

func (l *Contains) PostgresQuery() (string, pgx.NamedArgs)

type Expression

type Expression struct {
	Or []*OrCondition `@@ { "OR" @@ }`
}

func (*Expression) GetFields

func (e *Expression) GetFields() []string

func (*Expression) MongoExprQuery

func (e *Expression) MongoExprQuery() bson.M

func (*Expression) MongoQuery

func (e *Expression) MongoQuery() bson.M

func (*Expression) PostgresQuery

func (e *Expression) PostgresQuery(prefix string) (string, pgx.NamedArgs)

type Like

type Like struct {
	Operand *Operand `@@`
}

func (*Like) ExprQuery

func (l *Like) ExprQuery(op string) bson.M

func (*Like) MongoQuery

func (l *Like) MongoQuery() bson.M

func (*Like) NotPostgresQuery

func (l *Like) NotPostgresQuery() (string, pgx.NamedArgs)

func (*Like) PostgresQuery

func (l *Like) PostgresQuery() (string, pgx.NamedArgs)

type NotContains

type NotContains struct {
	Operand *Operand `@@`
}

func (*NotContains) ExprQuery

func (l *NotContains) ExprQuery(op string) bson.M

func (*NotContains) MongoQuery

func (l *NotContains) MongoQuery() bson.M

func (*NotContains) PostgresQuery

func (l *NotContains) PostgresQuery() (string, pgx.NamedArgs)

type NotLike

type NotLike struct {
	Operand *Operand `@@`
}

func (*NotLike) ExprQuery

func (l *NotLike) ExprQuery(op string) bson.M

func (*NotLike) MongoQuery

func (l *NotLike) MongoQuery() bson.M

func (*NotLike) NotPostgresQuery

func (l *NotLike) NotPostgresQuery() (string, pgx.NamedArgs)

func (*NotLike) PostgresQuery

func (l *NotLike) PostgresQuery() (string, pgx.NamedArgs)

type Operand

type Operand struct {
	Terms []*Term `@@ { @@ }`
}

func (*Operand) Val

func (o *Operand) Val() any

type OrCondition

type OrCondition struct {
	And []*Condition `@@ { "AND" @@ }`
}

func (*OrCondition) GetFields

func (c *OrCondition) GetFields() []string

func (*OrCondition) MongoExprQuery

func (c *OrCondition) MongoExprQuery() bson.M

func (*OrCondition) MongoQuery

func (c *OrCondition) MongoQuery() bson.M

func (*OrCondition) PostgresQuery

func (c *OrCondition) PostgresQuery(prefix string) (string, pgx.NamedArgs)

type Parser

type Parser interface {
	Parse(str string, isAllowedField func(f string) bool) (Query, error)
}

Parser parses expression.

func NewParser

func NewParser() Parser

NewParser creates new parser.

type Query

type Query interface {
	MongoQuery() bson.M
	PostgresQuery(prefix string) (string, pgx.NamedArgs)
	MongoExprQuery() bson.M
	GetFields() []string
}

type Term

type Term struct {
	Name        *string  `(@Ident`
	NumberFloat *float64 ` | @Float`
	NumberInt   *int     ` | @Int`
	Str         *string  ` | @String`
	Boolean     *Boolean ` | @("TRUE" | "FALSE")`
	Null        bool     ` | @"NULL" )`
}

func (*Term) Val

func (t *Term) Val() any

Jump to

Keyboard shortcuts

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