Home Manual Reference Source Test
import {Expression} from 'influx/src/builder.js'
public class | source

Expression

Expression is used to build filtering expressions, like those used in WHERE clauses. It can be used for fluent and safe building of queries using untrusted input.

Example:

e => e
  .field('host').equals.value('ares.peet.io')
  .or
  .field('host').matches(/example\.com$/)
  .or
  .expr(e => e
    .field('country').equals.value('US')
    .and
    .field('state').equals.value('WA'));

// Generates:
// "host" = 'ares.peet.io' OR "host" ~= /example\.com$/ OR \
//   ("county" = 'US' AND "state" = 'WA')

Member Summary

Public Members
public get

and: *

Chains on an AND clause to the expression.

public get

div: *

Chains on a / operator to the expression.

public get

Chains on a !` conditional to the expression to match regexes.

public get

equals: *

Chains on a = conditional to the expression.

public get

gt: *

Chains on a > conditional to the expression.

public get

gte: *

Chains on a >= conditional to the expression.

public get

lt: *

Chains on a < conditional to the expression.

public get

lte: *

Chains on a <= conditional to the expression.

public get

matches: *

Chains on a =~ conditional to the expression to match regexes.

public get

minus: *

Chains on a - operator to the expression.

public get

Chains on a != conditional to the expression.

public get

or: *

Chains on an OR clause to the expression.

public get

plus: *

Chains on a + operator to the expression.

public get

times: *

Chains on a * operator to the expression.

Method Summary

Public Methods
public

exp(fn: *): *

Inserts a subexpression; invokes the function with a new expression that can be chained on.

public

field(name: *): *

Inserts a field reference into the expression; the name will be automatically escaped.

public

tag(name: *): *

Inserts a tag reference into the expression; the name will be automatically escaped.

public

toString(): *

Converts the expression into its InfluxQL representation.

public

value(value: *): *

Value chains on a value to the expression.

Public Members

public get and: * source

Chains on an AND clause to the expression.

public get div: * source

Chains on a / operator to the expression.

public get doesntMatch: * source

Chains on a !` conditional to the expression to match regexes.

public get equals: * source

Chains on a = conditional to the expression.

public get gt: * source

Chains on a > conditional to the expression.

public get gte: * source

Chains on a >= conditional to the expression.

public get lt: * source

Chains on a < conditional to the expression.

public get lte: * source

Chains on a <= conditional to the expression.

public get matches: * source

Chains on a =~ conditional to the expression to match regexes.

public get minus: * source

Chains on a - operator to the expression.

public get notEqual: * source

Chains on a != conditional to the expression.

public get or: * source

Chains on an OR clause to the expression.

public get plus: * source

Chains on a + operator to the expression.

public get times: * source

Chains on a * operator to the expression.

Public Methods

public exp(fn: *): * source

Inserts a subexpression; invokes the function with a new expression that can be chained on.

Params:

NameTypeAttributeDescription
fn *

Return:

*

Example:

e.field('a').equals.value('b')
  .or.expr(e =>
    e.field('b').equals.value('b')
    .and.field('a').equals.value('c'))
  .toString()
// "a" = 'b' OR ("b" = 'b' AND "a" = 'c')

public field(name: *): * source

Inserts a field reference into the expression; the name will be automatically escaped.

Params:

NameTypeAttributeDescription
name *

Return:

*

public tag(name: *): * source

Inserts a tag reference into the expression; the name will be automatically escaped.

Params:

NameTypeAttributeDescription
name *

Return:

*

public toString(): * source

Converts the expression into its InfluxQL representation.

Return:

*

public value(value: *): * source

Value chains on a value to the expression.

  • Numbers will be inserted verbatim
  • Strings will be escaped and inserted
  • Booleans will be inserted correctly
  • Dates will be formatted and inserted correctly, including INanoDates.
  • Regular expressions will be inserted correctly, however an error will be thrown if they contain flags, as regex flags do not work in Influx
  • Otherwise we'll try to call .toString() on the value, throwing if we cannot do so.

Params:

NameTypeAttributeDescription
value *

Return:

*