query

package
v3.15.4 Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package query provides a parser for the right-hand side query part of the bloblang spec. This is useful as a separate package as it is used in isolation within interpolation functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecToBytes

func ExecToBytes(fn Function, ctx FunctionContext) []byte

ExecToBytes returns a byte slice from a function exection.

func ExecToString

func ExecToString(fn Function, ctx FunctionContext) string

ExecToString returns a string from a function exection.

func IClone

func IClone(root interface{}) interface{}

IClone performs a deep copy of a generic value.

func IGetBool

func IGetBool(v interface{}) (bool, error)

IGetBool takes a boxed value and attempts to extract a boolean from it.

func IGetInt

func IGetInt(v interface{}) (int64, error)

IGetInt takes a boxed value and attempts to extract an integer (int64) from it.

func IGetNumber

func IGetNumber(v interface{}) (float64, error)

IGetNumber takes a boxed value and attempts to extract a number (float64) from it.

func IIsNull

func IIsNull(i interface{}) bool

IIsNull returns whether a bloblang type is null, this includes Delete and Nothing types.

func ISanitize

func ISanitize(i interface{}) interface{}

ISanitize takes a boxed value of any type and attempts to convert it into one of the following types: string, []byte, int64, uint64, float64, bool, []interface{}, map[string]interface{}, Delete, Nothing.

func IToBytes

func IToBytes(i interface{}) []byte

IToBytes takes a boxed value of any type and attempts to convert it into a byte slice.

func IToString

func IToString(i interface{}) string

IToString takes a boxed value of any type and attempts to convert it into a string.

func ListFunctions

func ListFunctions() []string

ListFunctions returns a slice of function names, sorted alphabetically.

func ListMethods

func ListMethods() []string

ListMethods returns a slice of method names, sorted alphabetically.

func Parse

func Parse(input []rune) parser.Result

Parse parses an input into a query.Function.

func ParseDeprecated

func ParseDeprecated(input []rune) parser.Result

ParseDeprecated parses an input into a query.Function, but permits deprecated function interpolations. In order to support old functions this parser does not include field literals.

func RegisterFunction

func RegisterFunction(name string, allowDynamicArgs bool, ctor FunctionCtor, checks ...ArgCheckFn) struct{}

RegisterFunction to be accessible from Bloblang queries. Returns an empty struct in order to allow inline calls.

func RegisterMethod

func RegisterMethod(name string, allowDynamicArgs bool, ctor MethodCtor, checks ...ArgCheckFn) struct{}

RegisterMethod to be accessible from Bloblang queries. Returns an empty struct in order to allow inline calls.

Types

type ArgCheckFn

type ArgCheckFn func(args []interface{}) error

ArgCheckFn is an optional argument type checker for a function constructor.

func ExpectAtLeastOneArg

func ExpectAtLeastOneArg() ArgCheckFn

ExpectAtLeastOneArg returns an error unless >0 arguments are specified.

func ExpectBoolArg

func ExpectBoolArg(i int) ArgCheckFn

ExpectBoolArg returns an error if an argument i is not a boolean type.

func ExpectFloatArg

func ExpectFloatArg(i int) ArgCheckFn

ExpectFloatArg returns an error if an argument i is not a float type.

func ExpectIntArg

func ExpectIntArg(i int) ArgCheckFn

ExpectIntArg returns an error if an argument i is not an integer type.

func ExpectNArgs

func ExpectNArgs(i int) ArgCheckFn

ExpectNArgs returns an error unless exactly N arguments are specified.

func ExpectOneOrZeroArgs

func ExpectOneOrZeroArgs() ArgCheckFn

ExpectOneOrZeroArgs returns an error if more than one arg is specified.

func ExpectStringArg

func ExpectStringArg(i int) ArgCheckFn

ExpectStringArg returns an error if an argument i is not a string type (or a byte slice that can be converted).

type Delete

type Delete *struct{}

Delete is a special type that serializes to `null` when forced but indicates a target should be deleted.

type ErrRecoverable

type ErrRecoverable struct {
	Recovered interface{}
	Err       error
}

ErrRecoverable represents a function execution error that can optionally be recovered into a zero-value.

func (*ErrRecoverable) Error

func (e *ErrRecoverable) Error() string

Error implements the standard error interface.

type Function

type Function interface {
	// Execute this function for a message of a batch.
	Exec(ctx FunctionContext) (interface{}, error)
}

Function takes a set of contextual parameters and returns the result of the query.

func New

func New(query string) (Function, error)

New creates a new query function from a query string.

type FunctionContext

type FunctionContext struct {
	Value  *interface{}
	Maps   map[string]Function
	Vars   map[string]interface{}
	Index  int
	Msg    Message
	Legacy bool
}

FunctionContext provides access to a root message, its index within the batch, and

type FunctionCtor

type FunctionCtor func(args ...interface{}) (Function, error)

FunctionCtor constructs a new function from input arguments.

type Message

type Message interface {
	Get(p int) types.Part
	Len() int
}

Message is an interface type to be given to a query function, it allows the function to resolve fields and metadata from a message.

type MethodCtor

type MethodCtor func(target Function, args ...interface{}) (Function, error)

MethodCtor constructs a new method from a target function and input args.

type Nothing

type Nothing *struct{}

Nothing is a special type that serializes to `null` when forced but indicates a query should be disregarded (and not mapped).

Jump to

Keyboard shortcuts

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