query

package
v1.24.0-m3.5 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package query is inspired and partially copied from by github.com/cch123/elasticsql.

Index

Constants

This section is empty.

Variables

View Source
var (
	MalformedSqlQueryErrMessage = "malformed SQL query"
	NotSupportedErrMessage      = "operation is not supported"
	InvalidExpressionErrMessage = "invalid expression"
)

Functions

func NewConverterError

func NewConverterError(format string, a ...interface{}) error

func ParseExecutionDurationStr added in v1.23.0

func ParseExecutionDurationStr(durationStr string) (time.Duration, error)

func ParseSqlValue added in v1.20.0

func ParseSqlValue(sqlValue string) (interface{}, error)

ParseSqlValue returns a string, int64 or float64 if the parsing succeeds.

Types

type Converter

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

func NewConverter

func NewConverter(fnInterceptor FieldNameInterceptor, whereConverter ExprConverter) *Converter

func (*Converter) ConvertSql

func (c *Converter) ConvertSql(sql string) (*QueryParams, error)

ConvertSql transforms SQL to Elasticsearch query.

func (*Converter) ConvertWhereOrderBy

func (c *Converter) ConvertWhereOrderBy(whereOrderBy string) (*QueryParams, error)

ConvertWhereOrderBy transforms WHERE SQL statement to Elasticsearch query. It also supports ORDER BY clause.

type ConverterError

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

func (*ConverterError) Error

func (c *ConverterError) Error() string

func (*ConverterError) ToInvalidArgument added in v1.15.0

func (c *ConverterError) ToInvalidArgument() error

type ExprConverter

type ExprConverter interface {
	Convert(expr sqlparser.Expr) (elastic.Query, error)
}

func NewAndConverter

func NewAndConverter(whereConverter ExprConverter) ExprConverter

func NewComparisonExprConverter

func NewComparisonExprConverter(
	fnInterceptor FieldNameInterceptor,
	fvInterceptor FieldValuesInterceptor,
	allowedOperators map[string]struct{},
) ExprConverter

func NewIsConverter

func NewIsConverter(fnInterceptor FieldNameInterceptor) ExprConverter

func NewNotSupportedExprConverter

func NewNotSupportedExprConverter() ExprConverter

func NewOrConverter

func NewOrConverter(whereConverter ExprConverter) ExprConverter

func NewRangeCondConverter

func NewRangeCondConverter(
	fnInterceptor FieldNameInterceptor,
	fvInterceptor FieldValuesInterceptor,
	notBetweenSupported bool,
) ExprConverter

func NewWhereConverter

func NewWhereConverter(
	and ExprConverter,
	or ExprConverter,
	rangeCond ExprConverter,
	comparisonExpr ExprConverter,
	is ExprConverter) ExprConverter

type FieldNameInterceptor

type FieldNameInterceptor interface {
	Name(name string, usage FieldNameUsage) (string, error)
}

type FieldNameUsage

type FieldNameUsage int
const (
	FieldNameFilter FieldNameUsage = iota
	FieldNameSorter
	FieldNameGroupBy
)

type FieldValuesInterceptor

type FieldValuesInterceptor interface {
	Values(name string, values ...interface{}) ([]interface{}, error)
}

type NopFieldNameInterceptor

type NopFieldNameInterceptor struct{}

func (*NopFieldNameInterceptor) Name

type NopFieldValuesInterceptor

type NopFieldValuesInterceptor struct{}

func (*NopFieldValuesInterceptor) Values

func (n *NopFieldValuesInterceptor) Values(_ string, values ...interface{}) ([]interface{}, error)

type QueryParams added in v1.21.0

type QueryParams struct {
	Query   elastic.Query
	Sorter  []elastic.Sorter
	GroupBy []string
}

type WhereConverter

type WhereConverter struct {
	And            ExprConverter
	Or             ExprConverter
	RangeCond      ExprConverter
	ComparisonExpr ExprConverter
	Is             ExprConverter
}

func (*WhereConverter) Convert

func (w *WhereConverter) Convert(expr sqlparser.Expr) (elastic.Query, error)

Jump to

Keyboard shortcuts

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