lib/ustate/query_string.rb in ustate-client-0.0.2 vs lib/ustate/query_string.rb in ustate-client-0.0.3

- old
+ new

@@ -32,10 +32,16 @@ elements[1] end end module Or2 + def query + rest.elements.map { |x| x.and }.inject(first.query) do |a, sub| + Query::Or.new a, sub.query + end + end + def sql rest.elements.map { |x| x.and }. inject(first.sql) do |a, sub| a | sub.sql end @@ -133,10 +139,16 @@ elements[1] end end module And2 + def query + rest.elements.map { |x| x.primary }.inject(first.query) do |a, sub| + Query::And.new a, sub.query + end + end + def sql rest.elements.map { |x| x.primary }. inject(first.sql) do |a, sub| a & sub.sql end @@ -217,10 +229,14 @@ end end module Primary1 + def query + x.query + end + def sql x.sql end end @@ -346,10 +362,14 @@ elements[4] end end module Approximately1 + def query + Query::Approximately.new field.sql, string.sql + end + def sql Sequel::SQL::StringExpression.like field.sql, string.sql end end @@ -422,10 +442,14 @@ elements[4] end end module NotEquals1 + def query + Query::NotEquals.new field.sql, value.sql + end + def sql Sequel::SQL::BooleanExpression.from_value_pairs({field.sql => value.sql}, :AND, true) end end @@ -498,10 +522,14 @@ elements[4] end end module Equals1 + def query + Query::Equals.new field.sql, value.sql + end + def sql Sequel::SQL::BooleanExpression.from_value_pairs field.sql => value.sql end end @@ -527,24 +555,24 @@ r2 = instantiate_node(SyntaxNode,input, index...index) end s0 << r2 if r2 i4 = index - if has_terminal?('=', false, index) - r5 = instantiate_node(SyntaxNode,input, index...(index + 1)) - @index += 1 + if has_terminal?('==', false, index) + r5 = instantiate_node(SyntaxNode,input, index...(index + 2)) + @index += 2 else - terminal_parse_failure('=') + terminal_parse_failure('==') r5 = nil end if r5 r4 = r5 else - if has_terminal?('==', false, index) - r6 = instantiate_node(SyntaxNode,input, index...(index + 2)) - @index += 2 + if has_terminal?('=', false, index) + r6 = instantiate_node(SyntaxNode,input, index...(index + 1)) + @index += 1 else - terminal_parse_failure('==') + terminal_parse_failure('=') r6 = nil end if r6 r4 = r6 else