Skip to content

Commit 25dd4be

Browse files
committed
add IN and NOT IN conditions
1 parent 9e71a7b commit 25dd4be

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

lib/mysql_framework/sql_column.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,15 @@ def like(value)
6060
def not_like(value)
6161
SqlCondition.new(column: to_s, comparison: 'NOT LIKE', value: value)
6262
end
63+
64+
# This method is called to create an IN condition for this column.
65+
def in(value)
66+
SqlCondition.new(column: to_s, comparison: 'IN', value: value)
67+
end
68+
69+
# This method is called to create a NOT IN condition for this column.
70+
def not_in(value)
71+
SqlCondition.new(column: to_s, comparison: 'NOT IN', value: value)
72+
end
6373
end
6474
end

spec/lib/mysql_framework/sql_column_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,20 @@
8484
expect(condition.to_s).to eq('`gems`.`version` NOT LIKE ?')
8585
end
8686
end
87+
88+
describe '#in' do
89+
it 'returns a SqlCondition for the comparison' do
90+
condition = subject.in('(value_1, value_2, value_3)')
91+
expect(condition).to be_a(MysqlFramework::SqlCondition)
92+
expect(condition.to_s).to eq('`gems`.`version` IN ?')
93+
end
94+
end
95+
96+
describe '#not_in' do
97+
it 'returns a SqlCondition for the comparison' do
98+
condition = subject.not_in('(value_1, value_2, value_3)')
99+
expect(condition).to be_a(MysqlFramework::SqlCondition)
100+
expect(condition.to_s).to eq('`gems`.`version` NOT IN ?')
101+
end
102+
end
87103
end

0 commit comments

Comments
 (0)