ql

package
v0.0.0-...-a46f264 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package ql provides an API for building InfluxQL queries.

Currently it only supports 'SELECT' and and 'SHOW TAG VALUES' queries.

The builders will not ensure that the query returned will be a valid one in terms of completeness. The user of the package is responsible to compose a full query with the builder.

An example of a SELECT query:

ql.Select("a", "b").From("c").Where(ql.Eq(ql.And(), "a", "d", "g"))

Will return:

SELECT a, b FROM c WHERE a='d' AND a='g'

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	bytes.Buffer
	// contains filtered or unexported fields
}

Builder is the base builder for an Influx QL query.

func (*Builder) Append

func (b *Builder) Append(s string) *Builder

Append appens the given string to the query if it is a valid identifier.

func (*Builder) AppendWithComma

func (b *Builder) AppendWithComma(s ...string) *Builder

AppendWithComma appens the given strings and separates them with a comma.

func (*Builder) AppendWithQuotes

func (b *Builder) AppendWithQuotes(s string) *Builder

AppendWithQuotes appens the given string to the query builder with double quotes.

func (*Builder) AppendWithQuotesAndComma

func (b *Builder) AppendWithQuotesAndComma(s ...string) *Builder

AppendWithQuotesAndComma appens the given strings with double quotes and separates them with a comma.

func (Builder) Query

func (b Builder) Query() (string, []interface{})

type Operator

type Operator string
const (
	EQ      Operator = "="
	NEQ     Operator = "!="
	MATCH   Operator = "=~"
	NOMATCH Operator = "!~"
)

type OperatorBuilder

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

OperatorBuilder is a builder for combining WHERE clauses with AND and OR operators.

func And

func And() *OperatorBuilder

func Or

func Or() *OperatorBuilder

func (*OperatorBuilder) Query

func (o *OperatorBuilder) Query() (string, []interface{})

type Querier

type Querier interface {
	Query() (string, []interface{})
}

Querier interface provides the Query method.

func Eq

func Eq(join *OperatorBuilder, column string, values ...string) Querier

Eq returns a query part which compares column to each given value, joining them together with the given OperatorBuilder.

Eq(And(), "a", "b", "c") -> a='b' AND a='c'

func Gte

func Gte(join *OperatorBuilder, column string, values ...string) Querier

func Lte

func Lte(join *OperatorBuilder, column string, values ...string) Querier

func TimeRange

func TimeRange(from, to time.Time) Querier

type QueryFunc

type QueryFunc func() (string, []interface{})

The QueryFunc type is an adapter to allow the use of ordinary functions as Querier.

func (QueryFunc) Query

func (qf QueryFunc) Query() (string, []interface{})

Query calls qf()

type SelectBuilder

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

SelectBuilder is a builder for a 'SELECT' query.

func Select

func Select(columns ...string) *SelectBuilder

Select returns the base for building a 'SELECT' query.

func (*SelectBuilder) ASC

func (sb *SelectBuilder) ASC() *SelectBuilder

func (*SelectBuilder) From

func (sb *SelectBuilder) From(f ...string) *SelectBuilder

func (*SelectBuilder) GroupBy

func (sb *SelectBuilder) GroupBy(column string) *SelectBuilder

func (*SelectBuilder) Limit

func (sb *SelectBuilder) Limit(l int64) *SelectBuilder

func (*SelectBuilder) OrderBy

func (sb *SelectBuilder) OrderBy(column string) *SelectBuilder

func (*SelectBuilder) Query

func (sb *SelectBuilder) Query() (string, []interface{})

func (*SelectBuilder) TZ

func (sb *SelectBuilder) TZ(tz string) *SelectBuilder

func (*SelectBuilder) Where

func (sb *SelectBuilder) Where(q ...Querier) *SelectBuilder

type ShowMeasurementBuilder

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

ShowMeasurementBuilder is a builder for a 'SHOW MEASUREMENTS' query.

func ShowMeasurement

func ShowMeasurement() *ShowMeasurementBuilder

ShowMeasurement returns the base for building a 'SHOW MEASUREMENT' query.

func (*ShowMeasurementBuilder) Query

func (sm *ShowMeasurementBuilder) Query() (string, []interface{})

func (*ShowMeasurementBuilder) Where

func (*ShowMeasurementBuilder) With

type ShowTagValuesBuilder

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

ShowTagValuesBuilder is a builder for a 'SHOW TAG VALUES' query.

func ShowTagValues

func ShowTagValues() *ShowTagValuesBuilder

ShowTagValues returns the base for building a 'SHOW TAG VALUES' query.

func (*ShowTagValuesBuilder) From

func (*ShowTagValuesBuilder) Query

func (st *ShowTagValuesBuilder) Query() (string, []interface{})

func (*ShowTagValuesBuilder) Where

func (*ShowTagValuesBuilder) WithKeyIn

func (st *ShowTagValuesBuilder) WithKeyIn(tagKeys ...string) *ShowTagValuesBuilder

type WhereBuilder

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

WhereBuilder is a builder for the 'WHERE' clause of a query.

func Where

func Where(q ...Querier) *WhereBuilder

func (*WhereBuilder) Query

func (wb *WhereBuilder) Query() (string, []interface{})

Jump to

Keyboard shortcuts

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