Constructor
new FilterExpressionBuilder()
Do not instantiate this class directly. This is used by BaoModel.queryByIndex.
- Source
Methods
build(filter, model) → {Object|null}
Build a filter expression for a given filter and model.
Parameters:
Name | Type | Description |
---|---|---|
filter | Object | The filter object to build the expression for. The filter can contain:
|
model | BaoModel | The model to build the expression for. Used to validate field names. |
- Source
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' }
]
}