goflex

package module
v0.0.0-...-cedf259 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: MIT Imports: 7 Imported by: 0

README

DEPRECATED

Replaced by: https://github.com/golain-io/go-fluxbuilder

Go-Flex

Standardised Query Builder for FluxQL (InfluxDB 2.x)
Heavily inspired by github.com/Masterminds/squirrel

Why Builder Pattern?

From Calhoun.io :

The builder pattern is a technique where a developer uses a "builder" to construct an object. The end result could be anything - a string, a struct instance, or even a closure - but it is built using a builder. More often than not a builder is used because the object being created is complex and needs to be constructed in multiple steps, so the builder helps isolate each step and prevent bugs.

Example Code
import fluxq "github.com/golain-io/go-flex"

query := fluxq.From("sample-bucket").Range("-1h", "-30s")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClientNotSet = fmt.Errorf("cannot run; no Client set (Query)")

client not set error is reused in multiple different places

StatementBuilder is a parent builder for other builders, e.g. SelectBuilder.

Functions

func QueryWith

func QueryWith(api *influxapi.QueryAPI, f Fluxer) (res *influxapi.QueryTableResult, err error)

universal function to actually pass the generated query to the influxdb client results QueryTableResult as with the influx db client package

Types

type FilterBuilder

type FilterBuilder builder.Builder

filter builder type

func (FilterBuilder) And

func (b FilterBuilder) And(and string) FilterBuilder

func (FilterBuilder) Eq

func (FilterBuilder) Field

func (b FilterBuilder) Field(field string) FilterBuilder

func (FilterBuilder) GreaterThan

func (b FilterBuilder) GreaterThan(gt string) FilterBuilder

func (FilterBuilder) GreaterThanEq

func (b FilterBuilder) GreaterThanEq(gte string) FilterBuilder

func (FilterBuilder) LessThan

func (b FilterBuilder) LessThan(lt string) FilterBuilder

func (FilterBuilder) LessThanEq

func (b FilterBuilder) LessThanEq(lte string) FilterBuilder

func (FilterBuilder) Measurement

func (b FilterBuilder) Measurement(measurement string) FilterBuilder

func (FilterBuilder) NotEq

func (b FilterBuilder) NotEq(neq string) FilterBuilder

func (FilterBuilder) Or

func (FilterBuilder) Tag

func (b FilterBuilder) Tag(tag string) FilterBuilder

func (FilterBuilder) ToFlux

func (b FilterBuilder) ToFlux() (qString string, args []interface{}, err error)

generates string query to pass to influx client

type Fluxer

type Fluxer interface {
	ToFlux() (string, []interface{}, error)
}

Fluxer is the interface that wraps the ToFlux method.

ToFlux will return a FluxQL(string) representation of the Fluxer (with arguments) It may also return an error.

For variables within Builder types, ToFlux is consumed by the appendToFlux method which will append the result of ToFlux to the query string

[]interface{} is used to pass arguments to the query string

type FromBuilder

type FromBuilder builder.Builder

FromBuilder is the builder type for the from('bucket') function creates the actual fromQuery variable

func From

func From(bucket string) FromBuilder

From returns a new FromBuilder with the given bucket name.

func (FromBuilder) From

func (b FromBuilder) From(from string) FromBuilder

func (FromBuilder) Range

func (b FromBuilder) Range(t map[string]string) FromBuilder

func (FromBuilder) ToFlux

func (b FromBuilder) ToFlux() (qString string, args []interface{}, err error)

generates string query to pass to influx client

type StatementBuilderType

type StatementBuilderType builder.Builder

func (StatementBuilderType) From

Jump to

Keyboard shortcuts

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