Skip to content

Commit 9e71a7b

Browse files
committed
add LIKE and NOT LIKE conditions
1 parent f1a5ea8 commit 9e71a7b

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

lib/mysql_framework/sql_column.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,15 @@ def lte(value)
5050
def as(name)
5151
"#{self} as `#{name}`"
5252
end
53+
54+
# This method is called to create a LIKE condition for this column.
55+
def like(value)
56+
SqlCondition.new(column: to_s, comparison: 'LIKE', value: value)
57+
end
58+
59+
# This method is called to create a NOT LIKE condition for this column.
60+
def not_like(value)
61+
SqlCondition.new(column: to_s, comparison: 'NOT LIKE', value: value)
62+
end
5363
end
5464
end

lib/mysql_framework/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module MysqlFramework
4-
VERSION = '0.0.11'
4+
VERSION = '0.0.12'
55
end

spec/lib/mysql_framework/sql_column_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,20 @@
6868
expect(subject.as('v')).to eq('`gems`.`version` as `v`')
6969
end
7070
end
71+
72+
describe '#like' do
73+
it 'returns a SqlCondition for the comparison' do
74+
condition = subject.like('%foo%')
75+
expect(condition).to be_a(MysqlFramework::SqlCondition)
76+
expect(condition.to_s).to eq('`gems`.`version` LIKE ?')
77+
end
78+
end
79+
80+
describe '#not_like' do
81+
it 'returns a SqlCondition for the comparison' do
82+
condition = subject.not_like('%foo%')
83+
expect(condition).to be_a(MysqlFramework::SqlCondition)
84+
expect(condition.to_s).to eq('`gems`.`version` NOT LIKE ?')
85+
end
86+
end
7187
end

0 commit comments

Comments
 (0)