query

package module
v0.0.0-...-1588aab Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2018 License: BSD-3-Clause Imports: 8 Imported by: 4

README

query GoDoc

SQL-like query executor

Query language

It's like SQL, but not SQL. See below.

Supported features

  • SELECT * without a GROUP BY.
  • Basic WHERE clause
  • LIMIT

Unsupported features

These are unsupported at the moment.

  • GROUP BY
  • JOIN
  • ORDER BY

License

BSD (see LICENSE).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupported = errors.New("query: unsupported query")
)

Functions

This section is empty.

Types

type ColumnDesc

type ColumnDesc struct {
	Name      string `json:"name"`
	Aggregate string `json:"aggregate,omitempty"`
}

ColumnDesc describes a column.

type Cursor

type Cursor interface {
	Row() Row
	Next() bool
	Err() error
}

type Executor

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

Executor is a query executor.

func NewExecutor

func NewExecutor(table Table) *Executor

func (*Executor) Execute

func (e *Executor) Execute(query *Query) (*Result, error)

Execute executes a query and returns a set of rows for the result.

type Filter

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

func EqualsFilter

func EqualsFilter(column string, value interface{}) Filter

func GreaterThanFilter

func GreaterThanFilter(column string, value interface{}) Filter

func GreaterThanOrEqualFilter

func GreaterThanOrEqualFilter(column string, value interface{}) Filter

func LessThanFilter

func LessThanFilter(column string, value interface{}) Filter

func LessThanOrEqualFilter

func LessThanOrEqualFilter(column string, value interface{}) Filter

func MatchesFilter

func MatchesFilter(column string, r *regexp.Regexp) Filter

func NotEqualsFilter

func NotEqualsFilter(column string, value interface{}) Filter

func (Filter) Filter

func (f Filter) Filter(r Row) bool

type FilterDesc

type FilterDesc struct {
	Column   string      `json:"column"`
	Operator string      `json:"operator"`
	Value    interface{} `json:"value"`
}

FilterDesc represents a filter expression.

type FilterType

type FilterType int
const (
	FilterUnknown FilterType = iota
	FilterEquals
	FilterNotEquals
	FilterLessThan
	FilterLessThanOrEqual
	FilterGreaterThan
	FilterGreaterThanOrEqual
	FilterMatches
)

func (FilterType) String

func (f FilterType) String() string

type Query

type Query struct {
	Columns    []ColumnDesc `json:"columns,omitempty"`
	GroupBy    []ColumnDesc `json:"group_by,omitempty"`
	Filters    []FilterDesc `json:"filters,omitempty"`
	OrderBy    []ColumnDesc `json:"order_by,omitempty"`
	Descending bool         `json:"descending"`
	Limit      int          `json:"limit,omitempty"`
}

Query describes a query.

func Parse

func Parse(query string) (*Query, error)

func (Query) String

func (q Query) String() string

type Result

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

func (*Result) Rows

func (res *Result) Rows() []Row

type Row

type Row interface {
	Fields() []string
	Get(field string) (interface{}, bool)
}

type Table

type Table interface {
	NewCursor() (Cursor, error)
}

Jump to

Keyboard shortcuts

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