Skip to content

Commit 73dca2b

Browse files
authored
Merge pull request dynamodb-toolbox#89 from fredericbarthelet/allow-0-in-comparaison-operators
Allow 0 in comparaison operators
2 parents 470cb06 + 523ceaf commit 73dca2b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

__tests__/expressionBuilder.unit.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,15 @@ describe('expressionBuilder',() => {
342342
.toThrow(`A condition is required`)
343343
})
344344

345+
it('allows 0 in comparaison expression', () => {
346+
expect(() => expressionBuilder({ attr: 'a', lte: 0 },TestTable,'TestEntity'))
347+
.not.toThrow(`A condition is required`)
348+
expect(() => expressionBuilder({ attr: 'a', lt: 0 },TestTable,'TestEntity'))
349+
.not.toThrow(`A condition is required`)
350+
expect(() => expressionBuilder({ attr: 'a', gte: 0 },TestTable,'TestEntity'))
351+
.not.toThrow(`A condition is required`)
352+
expect(() => expressionBuilder({ attr: 'a', gt: 0 },TestTable,'TestEntity'))
353+
.not.toThrow(`A condition is required`)
354+
})
355+
345356
})

lib/expressionBuilder.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ const parseClause = (_clause,grp,table) => {
130130
if (eq !== undefined) { value = eq; f = 'eq'; operator = '=' }
131131
if (ne !== undefined) { value = value ? conditionError(f) : ne; f = 'ne'; operator = '<>' }
132132
if (_in) { value = value ? conditionError(f) : _in; f = 'in'; operator = 'IN' }
133-
if (lt) { value = value ? conditionError(f) : lt; f = 'lt'; operator = '<' }
134-
if (lte) { value = value ? conditionError(f) : lte; f = 'lte'; operator = '<=' }
135-
if (gt) { value = value ? conditionError(f) : gt; f = 'gt'; operator = '>' }
136-
if (gte) { value = value ? conditionError(f) : gte; f = 'gte'; operator = '>=' }
133+
if (lt !== undefined) { value = value ? conditionError(f) : lt; f = 'lt'; operator = '<' }
134+
if (lte !== undefined) { value = value ? conditionError(f) : lte; f = 'lte'; operator = '<=' }
135+
if (gt !== undefined) { value = value ? conditionError(f) : gt; f = 'gt'; operator = '>' }
136+
if (gte !== undefined) { value = value ? conditionError(f) : gte; f = 'gte'; operator = '>=' }
137137
if (between) { value = value ? conditionError(f) : between; f = 'between'; operator = 'BETWEEN' }
138138
if (exists !== undefined) { value = value ? conditionError(f) : exists; f = 'exists'; operator = 'EXISTS' }
139139
if (contains) { value = value ? conditionError(f) : contains; f = 'contains'; operator = 'CONTAINS' }

0 commit comments

Comments
 (0)