Options
All
  • Public
  • Public/Protected
  • All
Menu

Set of helper methods to build KeyConditionExpressions used in DynamoDB query and scan operations. All of the condition based methods return a KeyCondition.Resolver function in the form of '( name: string, exp: KeyCondition.Expression, type?: T,): string' this allow key conditions to be composed together and even extended in a very simple way.

See Key Condition Expression for details on how each of the below key comparison operations and functions work.

example

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

import { KeyCondition } from 'dynamodb-datamodel';
import { table } from './Table';

// Use KeyCondition to query the table with primary key of 'P-GUID' and sort key between (and including) 'a' and 'z'
const key = {
P: 'P-GUID',
S: KeyCondition.between('a', 'z'),
};
const params = table.queryParams(key);

expect(params).toEqual({
ExpressionAttributeNames: { '#n0': 'P', '#n1': 'S' },
ExpressionAttributeValues: { ':v0': 'P-GUID', ':v1': 'a', ':v2': 'z' },
KeyConditionExpression: '#n0 = :v0 AND #n1 BETWEEN :v1 AND :v2',
TableName: 'ExampleTable',
});

Hierarchy

  • KeyCondition

Index

Constructors

Methods

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

    example
    // Expands to: '#n0 = :v0 AND begins_with(#n1, :v1)'
    const key = {
    P: 'guid',
    S: KeyCondition.beginsWith('a')
    }
    const results = await table.query(key);

    Parameters

    • value: string

      String to check if the sort key value begins with.

    Returns KeyCondition.Resolver<Table.PrimaryKey.AttributeTypes>

    Resolver to use when generate key condition expression.

  • 'BETWEEN' - Between key condition compares if the sort key value is between two values.

    example
    // Expands to: '#n0 = :v0 AND #n1 BETWEEN :v1 AND :v2'
    const key = {
    P: 'guid',
    S: KeyCondition.between('a', 'z')
    }
    const results = await table.query(key);

    Type parameters

    Parameters

    • from: T

      Value to check if sort key is greater then and equal to.

    • to: T

      Value to check if sort key is less then and equal to.

    Returns KeyCondition.Resolver<Table.PrimaryKey.AttributeTypes>

    Resolver to use when generate key condition expression.

  • '=' - Equal condition compares if the sort key value is equal to a value.

    example
    // Expands to: '#n0 = :v0 AND #n1 = :v1'
    const key = {
    P: 'guid',
    S: KeyCondition.eq('value')
    }
    const results = await table.query(key);

    Type parameters

    Parameters

    • value: T

      Value to check if equal to.

    Returns KeyCondition.Resolver<Table.PrimaryKey.AttributeTypes>

    Resolver to use when generate key condition expression.

  • '>=' - Greater then or equal to condition compares if the sort key value is greater then or equal to a value.

    example
    // Expands to: '#n0 = :v0 AND #n1 >= :v1'
    const key = {
    P: 'guid',
    S: KeyCondition.ge('value')
    }
    const results = await table.query(key);

    Type parameters

    Parameters

    • value: T

      Value to check if greater then or equal to.

    Returns KeyCondition.Resolver<Table.PrimaryKey.AttributeTypes>

    Resolver to use when generate key condition expression.

  • '>' - Greater then condition compares if the sort key value is greater then a value.

    example
    // Expands to: '#n0 = :v0 AND #n1 > :v1'
    const key = {
    P: 'guid',
    S: KeyCondition.gt('value')
    }
    const results = await table.query(key);

    Type parameters

    Parameters

    • value: T

      Value to check if greater then.

    Returns KeyCondition.Resolver<Table.PrimaryKey.AttributeTypes>

    Resolver to use when generate key condition expression.

  • '<=' - Less then or equal to condition compares if the sort key value is less then or equal to a value.

    example
    // Expands to: '#n0 = :v0 AND #n1 <= :v1'
    const key = {
    P: 'guid',
    S: KeyCondition.le('value')
    }
    const results = await table.query(key);

    Type parameters

    Parameters

    • value: T

      Value to check if less then or equal to.

    Returns KeyCondition.Resolver<Table.PrimaryKey.AttributeTypes>

    Resolver to use when generate key condition expression.

  • '<' - Less then condition compares if the sort key value is less then a value.

    example
    // Expands to: '#n0 = :v0 AND #n1 < :v1'
    const key = {
    P: 'guid',
    S: KeyCondition.lt('value')
    }
    const results = await table.query(key);

    Type parameters

    Parameters

    • value: T

      Value to check if less then.

    Returns KeyCondition.Resolver<Table.PrimaryKey.AttributeTypes>

    Resolver to use when generate key condition expression.

Generated using TypeDoc