Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add LIKE, NOT LIKE conditions #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/mysql_framework/sql_column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,15 @@ def lte(value)
def as(name)
"#{self} as `#{name}`"
end

# This method is called to create a LIKE condition for this column.
def like(value)
SqlCondition.new(column: to_s, comparison: 'LIKE', value: value)
end

# This method is called to create a NOT LIKE condition for this column.
def not_like(value)
SqlCondition.new(column: to_s, comparison: 'NOT LIKE', value: value)
end
end
end
2 changes: 1 addition & 1 deletion lib/mysql_framework/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module MysqlFramework
VERSION = '0.0.11'
VERSION = '0.0.12'
end
16 changes: 16 additions & 0 deletions spec/lib/mysql_framework/sql_column_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,20 @@
expect(subject.as('v')).to eq('`gems`.`version` as `v`')
end
end

describe '#like' do
it 'returns a SqlCondition for the comparison' do
condition = subject.like('%foo%')
expect(condition).to be_a(MysqlFramework::SqlCondition)
expect(condition.to_s).to eq('`gems`.`version` LIKE ?')
end
end

describe '#not_like' do
it 'returns a SqlCondition for the comparison' do
condition = subject.not_like('%foo%')
expect(condition).to be_a(MysqlFramework::SqlCondition)
expect(condition.to_s).to eq('`gems`.`version` NOT LIKE ?')
end
end
end