query

package
v1.21.4 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 7 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 ParseSqlValue added in v1.20.0

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

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
)

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
}

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