From 9e71a7b3df776561cab33963d2b2a1d90d72c41d Mon Sep 17 00:00:00 2001 From: Neil Armstrong Date: Fri, 16 Nov 2018 11:17:48 +0000 Subject: [PATCH 1/3] add LIKE and NOT LIKE conditions --- lib/mysql_framework/sql_column.rb | 10 ++++++++++ lib/mysql_framework/version.rb | 2 +- spec/lib/mysql_framework/sql_column_spec.rb | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/mysql_framework/sql_column.rb b/lib/mysql_framework/sql_column.rb index 1f06562..d5d6618 100644 --- a/lib/mysql_framework/sql_column.rb +++ b/lib/mysql_framework/sql_column.rb @@ -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 diff --git a/lib/mysql_framework/version.rb b/lib/mysql_framework/version.rb index 8abd09c..da7ffed 100644 --- a/lib/mysql_framework/version.rb +++ b/lib/mysql_framework/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module MysqlFramework - VERSION = '0.0.11' + VERSION = '0.0.12' end diff --git a/spec/lib/mysql_framework/sql_column_spec.rb b/spec/lib/mysql_framework/sql_column_spec.rb index b1fbc27..0e2c042 100644 --- a/spec/lib/mysql_framework/sql_column_spec.rb +++ b/spec/lib/mysql_framework/sql_column_spec.rb @@ -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 From 25dd4befe13b7f10cbdd7f73d430e2eb5565dc57 Mon Sep 17 00:00:00 2001 From: Neil Armstrong Date: Fri, 16 Nov 2018 11:59:09 +0000 Subject: [PATCH 2/3] add IN and NOT IN conditions --- lib/mysql_framework/sql_column.rb | 10 ++++++++++ spec/lib/mysql_framework/sql_column_spec.rb | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/mysql_framework/sql_column.rb b/lib/mysql_framework/sql_column.rb index d5d6618..f207728 100644 --- a/lib/mysql_framework/sql_column.rb +++ b/lib/mysql_framework/sql_column.rb @@ -60,5 +60,15 @@ def like(value) def not_like(value) SqlCondition.new(column: to_s, comparison: 'NOT LIKE', value: value) end + + # This method is called to create an IN condition for this column. + def in(value) + SqlCondition.new(column: to_s, comparison: 'IN', value: value) + end + + # This method is called to create a NOT IN condition for this column. + def not_in(value) + SqlCondition.new(column: to_s, comparison: 'NOT IN', value: value) + end end end diff --git a/spec/lib/mysql_framework/sql_column_spec.rb b/spec/lib/mysql_framework/sql_column_spec.rb index 0e2c042..0e45145 100644 --- a/spec/lib/mysql_framework/sql_column_spec.rb +++ b/spec/lib/mysql_framework/sql_column_spec.rb @@ -84,4 +84,20 @@ expect(condition.to_s).to eq('`gems`.`version` NOT LIKE ?') end end + + describe '#in' do + it 'returns a SqlCondition for the comparison' do + condition = subject.in('(value_1, value_2, value_3)') + expect(condition).to be_a(MysqlFramework::SqlCondition) + expect(condition.to_s).to eq('`gems`.`version` IN ?') + end + end + + describe '#not_in' do + it 'returns a SqlCondition for the comparison' do + condition = subject.not_in('(value_1, value_2, value_3)') + expect(condition).to be_a(MysqlFramework::SqlCondition) + expect(condition.to_s).to eq('`gems`.`version` NOT IN ?') + end + end end From f4765e6dfb50a27c55b2a25175389fc0a42a9bb6 Mon Sep 17 00:00:00 2001 From: Neil Armstrong Date: Mon, 19 Nov 2018 11:36:27 +0000 Subject: [PATCH 3/3] revert IN/NOT as cant pass array in prepared sql statement --- lib/mysql_framework/sql_column.rb | 10 ---------- spec/lib/mysql_framework/sql_column_spec.rb | 16 ---------------- 2 files changed, 26 deletions(-) diff --git a/lib/mysql_framework/sql_column.rb b/lib/mysql_framework/sql_column.rb index f207728..d5d6618 100644 --- a/lib/mysql_framework/sql_column.rb +++ b/lib/mysql_framework/sql_column.rb @@ -60,15 +60,5 @@ def like(value) def not_like(value) SqlCondition.new(column: to_s, comparison: 'NOT LIKE', value: value) end - - # This method is called to create an IN condition for this column. - def in(value) - SqlCondition.new(column: to_s, comparison: 'IN', value: value) - end - - # This method is called to create a NOT IN condition for this column. - def not_in(value) - SqlCondition.new(column: to_s, comparison: 'NOT IN', value: value) - end end end diff --git a/spec/lib/mysql_framework/sql_column_spec.rb b/spec/lib/mysql_framework/sql_column_spec.rb index 0e45145..0e2c042 100644 --- a/spec/lib/mysql_framework/sql_column_spec.rb +++ b/spec/lib/mysql_framework/sql_column_spec.rb @@ -84,20 +84,4 @@ expect(condition.to_s).to eq('`gems`.`version` NOT LIKE ?') end end - - describe '#in' do - it 'returns a SqlCondition for the comparison' do - condition = subject.in('(value_1, value_2, value_3)') - expect(condition).to be_a(MysqlFramework::SqlCondition) - expect(condition.to_s).to eq('`gems`.`version` IN ?') - end - end - - describe '#not_in' do - it 'returns a SqlCondition for the comparison' do - condition = subject.not_in('(value_1, value_2, value_3)') - expect(condition).to be_a(MysqlFramework::SqlCondition) - expect(condition.to_s).to eq('`gems`.`version` NOT IN ?') - end - end end