Home Manual Reference Source Test
import {Expression} from 'influx'
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

Chains on an AND clause to the expression.

public get

Chains on a / operator to the expression.

public get

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

public get

Chains on a = conditional to the expression.

public get

Chains on a > conditional to the expression.

public get

Chains on a >= conditional to the expression.

public get

Chains on a < conditional to the expression.

public get

Chains on a <= conditional to the expression.

public get

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

public get

Chains on a - operator to the expression.

public get

Chains on a != conditional to the expression.

public get

Chains on an OR clause to the expression.

public get

Chains on a + operator to the expression.

public get

Chains on a * operator to the expression.

Method Summary

Public Methods
public

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

public

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

public

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

public

Converts the expression into its InfluxQL representation.

public

value(value: *): Expression

Value chains on a value to the expression.

Public Members

public get and: Expression source

Chains on an AND clause to the expression.

public get div: Expression source

Chains on a / operator to the expression.

public get doesntMatch: Expression source

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

public get equals: Expression source

Chains on a = conditional to the expression.

public get gt: Expression source

Chains on a > conditional to the expression.

public get gte: Expression source

Chains on a >= conditional to the expression.

public get lt: Expression source

Chains on a < conditional to the expression.

public get lte: Expression source

Chains on a <= conditional to the expression.

public get matches: Expression source

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

public get minus: Expression source

Chains on a - operator to the expression.

public get notEqual: Expression source

Chains on a != conditional to the expression.

public get or: Expression source

Chains on an OR clause to the expression.

public get plus: Expression source

Chains on a + operator to the expression.

public get times: Expression source

Chains on a * operator to the expression.

Public Methods

public exp(fn: function(e: Expression): Expression): Expression source

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

Params:

NameTypeAttributeDescription
fn function(e: Expression): Expression

Return:

Expression

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: String): Expression source

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

Params:

NameTypeAttributeDescription
name String

Return:

Expression

public tag(name: String): Expression source

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

Params:

NameTypeAttributeDescription
name String

Return:

Expression

public toString(): String source

Converts the expression into its InfluxQL representation.

Return:

String

public value(value: *): Expression 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:

Expression