FilterExpressionBuilder

Supporting class for building DynamoDB filter expressions.

Constructor

new FilterExpressionBuilder()

Do not instantiate this class directly. This is used by BaoModel.queryByIndex.

Methods

build(filter, model) → {Object|null}

Build a filter expression for a given filter and model.

Parameters:
NameTypeDescription
filterObject

The filter object to build the expression for. The filter can contain:

  • Simple field comparisons: { fieldName: value } for exact matches
  • Comparison operators: { fieldName: { $eq: value, $ne: value, $gt: value, $gte: value, $lt: value, $lte: value } }
  • String operators: { fieldName: { $beginsWith: value, $contains: value } }
  • Logical operators:
    • $and: [{condition1}, {condition2}] - All conditions must match
    • $or: [{condition1}, {condition2}] - At least one condition must match
    • $not: {condition} - Condition must not match
modelBaoModel

The model to build the expression for. Used to validate field names.

Returns:

Returns null if no filter provided, otherwise returns an object containing:

  • FilterExpression: String DynamoDB filter expression
  • ExpressionAttributeNames: Map of attribute name placeholders
  • ExpressionAttributeValues: Map of attribute value placeholders
Type: 
Object | null
Example
filterExp1 = {
    status: 'active',  // Exact match
}

filterExp2 = {
    age: { $gt: 21 },  // Greater than comparison
}

filterExp3 = {
    roles: { $contains: 'admin' }, // String contains
}

filterExp4 = {
    // OR condition
    $or: [
      { type: 'user' },
      { type: 'admin' }
    ]
  }