-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from gabynaiman/nql_array_node
Nql array node
- Loading branch information
Showing
40 changed files
with
951 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Rasti | ||
module DB | ||
module NQL | ||
module FilterConditionStrategies | ||
class Base | ||
|
||
def filter_condition_for(comparison_name, identifier, argument) | ||
type = type_for argument | ||
raise UnsupportedTypeComparison.new(type, comparison_name) unless type.respond_to?(comparison_name) | ||
type.public_send comparison_name, identifier, argument.value | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Rasti | ||
module DB | ||
module NQL | ||
module FilterConditionStrategies | ||
class Postgres < Base | ||
|
||
PG_TYPES = { | ||
array: Types::PGArray | ||
} | ||
|
||
private | ||
|
||
def type_for(argument) | ||
PG_TYPES.fetch(argument.type, Types::Generic) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Rasti | ||
module DB | ||
module NQL | ||
module FilterConditionStrategies | ||
class SQLite < Base | ||
|
||
SQLITE_TYPES = { | ||
array: Types::SQLiteArray | ||
} | ||
|
||
private | ||
|
||
def type_for(argument) | ||
SQLITE_TYPES.fetch(argument.type, Types::Generic) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
49 changes: 49 additions & 0 deletions
49
lib/rasti/db/nql/filter_condition_strategies/types/generic.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Rasti | ||
module DB | ||
module NQL | ||
module FilterConditionStrategies | ||
module Types | ||
class Generic | ||
|
||
def self.equal(identifier, value) | ||
{identifier => value} | ||
end | ||
|
||
def self.not_equal(identifier, value) | ||
Sequel.negate equal(identifier, value) | ||
end | ||
|
||
def self.greater_than(identifier, value) | ||
identifier > value | ||
end | ||
|
||
def self.greater_than_or_equal(identifier, value) | ||
identifier >= value | ||
end | ||
|
||
def self.less_than(identifier, value) | ||
identifier < value | ||
end | ||
|
||
def self.less_than_or_equal(identifier, value) | ||
identifier <= value | ||
end | ||
|
||
def self.like(identifier, value) | ||
Sequel.ilike identifier, value | ||
end | ||
|
||
def self.include(identifier, value) | ||
Sequel.ilike identifier, "%#{value}%" | ||
end | ||
|
||
def self.not_include(identifier, value) | ||
~include(identifier, value) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
lib/rasti/db/nql/filter_condition_strategies/types/pg_array.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Rasti | ||
module DB | ||
module NQL | ||
module FilterConditionStrategies | ||
module Types | ||
class PGArray | ||
|
||
def self.equal(identifier, values) | ||
Sequel.&( | ||
Sequel.pg_array(identifier).contains(Sequel.pg_array(values)), | ||
Sequel.pg_array(identifier).contained_by(Sequel.pg_array(values)) | ||
) | ||
end | ||
|
||
def self.not_equal(identifier, values) | ||
~equal(identifier, values) | ||
end | ||
|
||
def self.include(identifier, values) | ||
Sequel.pg_array(identifier).overlaps Sequel.pg_array(values) | ||
end | ||
|
||
def self.not_include(identifier, values) | ||
~include(identifier, values) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
34 changes: 34 additions & 0 deletions
34
lib/rasti/db/nql/filter_condition_strategies/types/sqlite_array.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Rasti | ||
module DB | ||
module NQL | ||
module FilterConditionStrategies | ||
module Types | ||
class SQLiteArray | ||
|
||
def self.equal(identifier, values) | ||
array = values.map { |value| "\"#{value}\"" }.join(',') | ||
{identifier => "[#{array}]"} | ||
end | ||
|
||
def self.not_equal(identifier, values) | ||
Sequel.|(*values.map { |value| ~Sequel.like(identifier, "%\"#{value}\"%") }) | ||
end | ||
|
||
def self.like(identifier, values) | ||
Sequel.|(*values.map { |value| Sequel.like(identifier, "%#{value}%") }) | ||
end | ||
|
||
def self.include(identifier, values) | ||
Sequel.|(*values.map { |value| Sequel.like(identifier, "%\"#{value}\"%") }) | ||
end | ||
|
||
def self.not_include(identifier, values) | ||
Sequel.&(*values.map { |value| ~Sequel.like(identifier, "%\"#{value}\"%") }) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
lib/rasti/db/nql/filter_condition_strategies/unsupported_type_comparison.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Rasti | ||
module DB | ||
module NQL | ||
module FilterConditionStrategies | ||
class UnsupportedTypeComparison < StandardError | ||
|
||
attr_reader :argument_type, :comparison_name | ||
|
||
def initialize(argument_type, comparison_name) | ||
@argument_type = argument_type | ||
@comparison_name = comparison_name | ||
end | ||
|
||
def message | ||
"Unsupported comparison #{comparison_name} for #{argument_type}" | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Rasti | ||
module DB | ||
module NQL | ||
module Nodes | ||
class ArrayContent < Treetop::Runtime::SyntaxNode | ||
|
||
def values | ||
[left.value] + right_value | ||
end | ||
|
||
private | ||
|
||
def right_value | ||
right.is_a?(self.class) ? right.values : [right.value] | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.