Skip to content

Commit

Permalink
fix: using not contains query filter
Browse files Browse the repository at this point in the history
We were using `not_contains` as the function name in DynamoDB filter
expressions, but DynamoDB throws an error `Invalid FilterExpression:
Invalid function name; function: not_contains`. The proper function name
is simply `not contains`.
  • Loading branch information
benhutchins committed Mar 7, 2024
1 parent c908131 commit 98d3c7f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/query/expression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,21 @@ describe('query/expression', () => {
':v1': { BOOL: true },
},
})

expect(buildQueryExpression(schema, {
someString: ['not contains', 'hello world'],
someBool: true,
})).to.deep.equal({
FilterExpression: 'not contains(#a0, :v0) AND #a1 = :v1',
ExpressionAttributeNames: {
'#a0': 'someString',
'#a1': 'someBool',
},
ExpressionAttributeValues: {
':v0': { S: 'hello world' },
':v1': { BOOL: true },
},
})
})

it('works with includes/IN operator', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/query/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class FilterExpressionQuery<T extends Table> {
strValue = { B: _.isArray(strValue.BS) ? strValue.BS[0] : strValue.BS }
}

const queryOperator = operator === 'beginsWith' ? 'begins_with' : operator.replace(/ /g, '_')
const queryOperator = operator === 'beginsWith' ? 'begins_with' : operator
query = `${queryOperator}(${attrNameMappedTo}, ${variableName})`
values[variableName] = strValue
break
Expand Down

0 comments on commit 98d3c7f

Please sign in to comment.