pageql

package
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Ident      = `\b([a-zA-Z][.a-zA-Z0-9]*)\b`
	Int        = `\b(\d+)\b`
	Float      = `\b(\d*\.\d+)\b`
	String     = `'[^']*'|"[^"]*"`
	Regexp     = `/(.+?)/|\!(.+?)\!|\@(.+?)\@|\~(.+?)\~`
	Operators  = `==|=\~|\!=|\!\~|[.,()]`
	Whitespace = `\s+`
)

Variables

This section is empty.

Functions

func CompileQuery

func CompileQuery(query string) (stmnt *Statement, err *ParseError)

func CompileSelect

func CompileSelect(query string) (sel *Selection, err *ParseError)

func Match

func Match(query string, ctx context.Context) (matched bool, err error)

func SanitizeQuery

func SanitizeQuery(query string) (sanitized string)

func UnquoteRegexp

func UnquoteRegexp(s string) (out string, err error)

func UnquoteString

func UnquoteString(s string) (out string, err error)

Types

type Boolean

type Boolean bool

func (*Boolean) Capture

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

type Condition

type Condition struct {
	Left  *Expression `parser:"'(' @@" json:"left"`
	Type  string      `parser:"@( 'AND' | 'OR' )" json:"type"`
	Right *Expression `parser:"@@ ')'" json:"right"`
}

func (*Condition) Render

func (c *Condition) Render() (clone *Condition)

type Expression

type Expression struct {
	Condition *Condition `parser:"( @@ )?" json:"condition,omitempty"`
	Operation *Operation `parser:"( @@ )?" json:"operation,omitempty"`
}

func (*Expression) Render

func (e *Expression) Render() (clone *Expression)

type Nil

type Nil bool

func (*Nil) Capture

func (n *Nil) Capture(values []string) error

type Operation

type Operation struct {
	Left  *string `parser:" '(' '.' @Ident" json:"left"`
	Type  string  `parser:"  ( @'!=' | @'==' | @'=~' | @'!~' )" json:"type"`
	Right *Value  `parser:"  @@ ')'" json:"right"`
}

func (*Operation) Render

func (o *Operation) Render() (clone *Operation)

type ParseError

type ParseError struct {
	Query   string
	Column  int
	Message string
	// contains filtered or unexported fields
}

func (*ParseError) Error

func (e *ParseError) Error() (msg string)

func (*ParseError) Pretty

func (e *ParseError) Pretty() (refined string)

type Selecting

type Selecting struct {
	Count      bool   `parser:"( @'COUNT' )?" json:"count,omitempty"`
	Random     bool   `parser:"( @'RANDOM' )?" json:"random,omitempty"`
	Distinct   bool   `parser:"( @'DISTINCT' )?" json:"distinct,omitempty"`
	ContextKey string `parser:" '.' @Ident" json:"context-key"`
}

func (*Selecting) Render

func (s *Selecting) Render() (out *Selecting)

func (*Selecting) String

func (s *Selecting) String() (query string)

type Selection

type Selection struct {
	Selecting []*Selecting `parser:"'SELECT' @@ ( ',' @@ )*" json:"selecting,omitempty"`
	Statement *Statement   `parser:"( 'WITHIN' @@ )?" json:"statement,omitempty"`
}

func (*Selection) Render

func (s *Selection) Render() (out *Selection)

func (*Selection) String

func (s *Selection) String() (query string)

func (*Selection) Stringify

func (s *Selection) Stringify() (out string)

type Statement

type Statement struct {
	Expression  *Expression `parser:"@@" json:"expressions,omitempty"`
	Limit       *Value      `parser:"( 'LIMIT' @@ )?" json:"limit,omitempty"`
	Offset      *Value      `parser:"( 'OFFSET' @@ )?" json:"offset,omitempty"`
	OrderBy     *string     `parser:"( 'ORDER' 'BY' '.' @Ident )?" json:"order-by,omitempty"`
	SortDir     *string     `parser:"( @'ASC' | @'DSC' | @'DESC' )?" json:"sort-dir,omitempty"`
	ContextKeys []string    `parser:"" json:"context-keys,omitempty"`
	// contains filtered or unexported fields
}

func (*Statement) Render

func (s *Statement) Render() (out *Statement)

func (*Statement) String

func (s *Statement) String() (query string)

func (*Statement) Stringify

func (s *Statement) Stringify() (out string)

type Value

type Value struct {
	ContextKey *string  `parser:"  ( '.' @Ident )" json:"context-key,omitempty"`
	Regexp     *string  `parser:"| ( 'm' @Regexp )" json:"regexp,omitempty"`
	String     *string  `parser:"| ( @String )" json:"string,omitempty"`
	Int        *int     `parser:"| ( @Int )" json:"int,omitempty"`
	Float      *float64 `parser:"| ( @Float )" json:"float,omitempty"`
	Bool       *Boolean `parser:"| @( 'true' | 'false' )" json:"bool,omitempty"`
	Nil        *Nil     `parser:"| @( 'nil' )" json:"nil,omitempty"`
}

func (*Value) Render

func (v *Value) Render() (clone *Value)

Jump to

Keyboard shortcuts

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