Skip to content

Commit

Permalink
Support NE condition operator
Browse files Browse the repository at this point in the history
  • Loading branch information
andrykonchin committed Mar 10, 2018
1 parent 46b1784 commit a82e881
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/dynamoid/adapter_plugin/aws_sdk_v2.rb
Expand Up @@ -18,6 +18,7 @@ class AwsSdkV2
# we declare schema in models
FIELD_MAP = {
eq: 'EQ',
ne: 'NE',
gt: 'GT',
lt: 'LT',
gte: 'GE',
Expand Down
2 changes: 2 additions & 0 deletions lib/dynamoid/criteria/chain.rb
Expand Up @@ -196,6 +196,8 @@ def field_hash(key)
val = type_cast_condition_parameter(name, query[key])

hash = case operation
when 'ne'
{ ne: val }
when 'gt'
{ gt: val }
when 'lt'
Expand Down
14 changes: 14 additions & 0 deletions spec/dynamoid/criteria/chain_spec.rb
Expand Up @@ -247,6 +247,13 @@ def request_params
expect(chain.where(id: 1, array: [1, 2]).all).to contain_exactly(document1)
end

it 'supports ne' do
customer1 = model.create(name: 'a', last_name: 'a', age: 5)
customer2 = model.create(name: 'a', last_name: 'b', age: 9)

expect(model.where(name: 'a', 'age.ne' => 9).all).to contain_exactly(customer1)
end

it 'supports lt' do
customer1 = model.create(name: 'a', last_name: 'a', age: 5)
customer2 = model.create(name: 'a', last_name: 'b', age: 9)
Expand Down Expand Up @@ -388,6 +395,13 @@ def request_params
expect(klass.where(array: ['a', 'b']).all).to contain_exactly(document1)
end

it 'supports ne' do
customer1 = model.create(age: 5)
customer2 = model.create(age: 9)

expect(model.where('age.ne' => 9).all).to contain_exactly(customer1)
end

it 'supports lt' do
customer1 = model.create(age: 5)
customer2 = model.create(age: 9)
Expand Down

0 comments on commit a82e881

Please sign in to comment.