Options
All
  • Public
  • Public/Protected
  • All
Menu

Set of helper methods to build ConditionExpressions used in DynamoDB delete, put and update operations, and FilterExpression used in DynamoDB query and scan operations. All of the condition based methods return a Condition.Resolver function in the form of '(exp: ConditionExpression): string' this allow conditions to be composed together and even extended in a very simple way.

See Comparison Operator and Function Reference for details on how each of the below comparison operations and functions work.

Condition is also used by {@link fields} to allow each field type to only expose the conditions that the field supports.

example

examples/Condition.ts, (imports: examples/Table.ts)

import { Condition, Table } from 'dynamodb-datamodel';

// Destructuring methods from Condition to make writing expression more concise
const { eq, ne, and, path } = Condition;
const condition = and(eq('first', 'john'), eq('last', 'smith'), ne('first', path('nickname')));

// Table params generate for condition
expect(Table.addParams({}, { conditions: [condition] })).toEqual({
ConditionExpression: '(#n0 = :v0 AND #n1 = :v1 AND #n0 <> #n2)',
ExpressionAttributeNames: { '#n0': 'first', '#n1': 'last', '#n2': 'nickname' },
ExpressionAttributeValues: { ':v0': 'john', ':v1': 'smith' },
});

Note: Condition is a class that contains only static methods to support using javascript reserved words as method names, like 'in'. Condition is also a namespace to scope the Condition specific typings, like Resolver.

Hierarchy

  • Condition

Index

Constructors

Methods

  • 'AND' - And logical evaluations check if all sub condition is true. This condition will be evaluated with an outer '()' to ensure proper order of evaluation.

    example
    // Expands to: '(#n0 = :v0 AND #n0 = :v1 AND #n0 = :v2)'
    const condition = Condition.and(Condition.eq('name', 1), Condition.eq('name', 2), Condition.eq('name', 3));

    Parameters

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • 'begins_with' - Begins with function checks to see if a string attribute begins with a string value. Supported Types: String

    example
    // Expands to: 'begins_with(#n0, :v0)'
    const condition = Condition.beginsWith('name', 'value');

    Parameters

    • path: string

      Path to attribute to get the value from.

    • value: string

      String to check if the path attribute value begins with.

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • 'BETWEEN' - Between condition compares if an attribute value is between two values or other attributes. Condition.between('path', 1, 2) will have the same outcome as Condition.and(Condition.ge('path', 1), Condition.le('path', 2))

    example
    // Expands to: '#n0 BETWEEN :v0 AND :v1'
    const condition = Condition.between('name', 1, 2);

    Parameters

    • path: string

      Path to attribute or size of attribute to compare.

    • from: Value<Table.AttributeValues>

      Value (or path to attribute) to check if greater then and equal to.

    • to: Value<Table.AttributeValues>

      Value (or path to attribute) to check if less then and equal to.

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • 'contains' Contains function checks if the attribute string or set contains the string value.

    example
    // Expands to: 'contains(#n0, :v0)'
    const condition = Condition.contains('name', 'value');

    Supported Types: String, *Set

    Parameters

    • path: string

      Path to attribute to get the value from.

    • value: string

      String to check if the attribute value contains.

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • '=' - Equal condition compares if an attribute value is equal to a value or another attribute.

    example
    // Expands to: '#n0 = :v0'
    const condition = Condition.eq('name', 'value');

    Parameters

    • left: Path

      Path to attribute or size of attribute to compare.

    • right: Value<Table.AttributeValues>

      Value (or path to attribute) to check if equal to.

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • 'attribute_exists' - Attribute exists function check if the attribute exists for the item.

    example
    // Expands to: 'attribute_exists(#n0)'
    const condition = Condition.exists('name');

    Parameters

    • path: string

      Path to attribute to get the value from.

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • '>=' - Greater then or equal to condition compare sif an attribute value is greater then or equal to a value or another attribute.

    example
    // Expands to: '#n0 >= :v0'
    const condition = Condition.ge('name', 'value');

    Parameters

    • left: Path

      Path to attribute or size of attribute to compare.

    • right: Value<Table.AttributeValues>

      Value (or path to attribute) to check if greater then or equal to.

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • '>' - Greater then condition compares if an attribute value is greater then a value or another attribute.

    example
    // Expands to: '#n0 > :v0'
    const condition = Condition.gt('name', 'value');

    Parameters

    • left: Path

      Path to attribute or size of attribute to compare.

    • right: Value<Table.AttributeValues>

      Value (or path to attribute) to check if greater then.

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • 'IN' - In condition compares the value of an attribute is equal to any of the list values or other attributes.

    example
    // Expands to: '#n0 IN (:v0, :v1, :v2)'
    const condition = Condition.in('name', [1, 2, 3]);

    Parameters

    • path: string

      Path to attribute to get the value from.

    • values: Value<Table.AttributeValues>[]

      List of the values to check if equal to path attribute value.

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • '<=' - Less then or equal to condition compares if an attribute value is less then or equal to a value or another attribute.

    example
    // Expands to: '#n0 <= :v0'
    const condition = Condition.le('name', 'value');

    Parameters

    • left: Path

      Path to attribute or size of attribute to compare.

    • right: Value<Table.AttributeValues>

      Value (or path to attribute) to check if less then or equal to.

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • '<' - Less then condition compares if an attribute value is less then a value or another attribute.

    example
    // Expands to: '#n0 < :v0'
    const condition = Condition.lt('name', 'value');

    Parameters

    • left: Path

      Path to attribute or size of attribute to compare.

    • right: Value<Table.AttributeValues>

      Value (or path to attribute) to check if less then.

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • '<>' - Not equal condition compares if an attribute value is not equal to a value or another attribute.

    example
    // Expands to: '#n0 <> :v0'
    const condition = Condition.ne('name', 'value');

    Parameters

    • left: Path

      Path to attribute or size of attribute to compare.

    • right: Value<Table.AttributeValues>

      Value (or path to attribute) to check if not equal to.

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • 'NOT' - Not logical evaluations inverts the condition so true is now false or false is now true. This condition will be evaluated with an outer '()' to ensure proper order of evaluation.

    example
    // Expands to: '(NOT #n0 = :v0)'
    const condition = Condition.not(Condition.eq('name', 1));

    Parameters

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • 'attribute_not_exists' - Attribute not exists function checks if the attribute does not exists for the item.

    example
    // Expands to: 'attribute_not_exists(#n0)'
    const condition = Condition.notExists('name');

    Parameters

    • path: string

      Path to attribute to get the value from.

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • 'OR' - Or logical evaluations check if at least one sub condition is true. This condition will be evaluated with an outer '()' to ensure proper order of evaluation.

    example
    // Expands to: '(#n0 = :v0 OR #n0 = :v1 OR #n0 = :v2)'
    const condition = Condition.or(Condition.eq('name', 1), Condition.eq('name', 2), Condition.eq('name', 3));

    Parameters

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

  • Inserts a path for a value in below conditions methods to allow conditions to compare two fields against each other.

    example
    // Expands to: '#n0 = #n1'
    const condition = Condition.eq('name', Condition.path('nickname'));

    Parameters

    • value: string

      Path to use for a condition value.

    Returns ValueResolver

    Resolver to use when generate condition expression.

  • Inserts the size of the attribute value to compare the data size to a static value or another attribute value.

    Supported Types:

    • String: length of string.
    • Binary: number of bytes in value.
    • *Set: number of elements in set.
    • Map: number of child elements.
    • List: number of child elements.
    example
    // Expands to: 'size(#n0) = :v0'
    const condition = Condition.eq(Condition.size('name'), 4);

    Parameters

    • path: string

      Attribute path to get size of value for.

    Returns ValueResolver

    Resolver to use when generate condition expression.

  • 'attribute_type' - Attribute type function checks to see if the attribute is of a certain data type.

    example
    // Expands to: 'attribute_type(#n0, :v0)'
    const condition = Condition.type('name', 'S');

    Parameters

    • path: string

      Path to attribute to get the value from.

    • type: Table.AttributeTypes

      Type to check that the path attribute value matches.

    Returns Condition.Resolver

    Resolver to use when generate condition expression.

Generated using TypeDoc