Class: Dbee::Query
- Inherits:
-
Object
- Object
- Dbee::Query
- Extended by:
- Forwardable
- Defined in:
- lib/dbee/query.rb,
lib/dbee/query/field.rb,
lib/dbee/query/filters.rb,
lib/dbee/query/sorters.rb,
lib/dbee/query/filters/base.rb,
lib/dbee/query/sorters/base.rb,
lib/dbee/query/filters/equals.rb,
lib/dbee/query/filters/contains.rb,
lib/dbee/query/filters/less_than.rb,
lib/dbee/query/sorters/ascending.rb,
lib/dbee/query/filters/not_equals.rb,
lib/dbee/query/sorters/descending.rb,
lib/dbee/query/filters/not_contain.rb,
lib/dbee/query/filters/starts_with.rb,
lib/dbee/query/filters/greater_than.rb,
lib/dbee/query/filters/not_start_with.rb,
lib/dbee/query/filters/less_than_or_equal_to.rb,
lib/dbee/query/filters/greater_than_or_equal_to.rb
Overview
This class is an abstration of a simplified SQL expression. In DB terms:
-
fields are the SELECT
-
sorters are the ORDER BY
-
limit is the TAKE
-
filters are the WHERE
Defined Under Namespace
Classes: Field, Filters, Sorters
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#sorters ⇒ Object
readonly
Returns the value of attribute sorters.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#initialize(fields: [], from: nil, filters: [], limit: nil, offset: nil, sorters: []) ⇒ Query
constructor
A new instance of Query.
- #key_chain ⇒ Object
Constructor Details
#initialize(fields: [], from: nil, filters: [], limit: nil, offset: nil, sorters: []) ⇒ Query
Returns a new instance of Query.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dbee/query.rb', line 35 def initialize( fields: [], from: nil, filters: [], limit: nil, offset: nil, sorters: [] ) @fields = Field.array(fields) @filters = Filters.array(filters).uniq @from = from.to_s @limit = limit.to_s.empty? ? nil : limit.to_i @offset = offset.to_s.empty? ? nil : offset.to_i @sorters = Sorters.array(sorters).uniq freeze end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
24 25 26 |
# File 'lib/dbee/query.rb', line 24 def fields @fields end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
24 25 26 |
# File 'lib/dbee/query.rb', line 24 def filters @filters end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
24 25 26 |
# File 'lib/dbee/query.rb', line 24 def from @from end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
24 25 26 |
# File 'lib/dbee/query.rb', line 24 def limit @limit end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
24 25 26 |
# File 'lib/dbee/query.rb', line 24 def offset @offset end |
#sorters ⇒ Object (readonly)
Returns the value of attribute sorters.
24 25 26 |
# File 'lib/dbee/query.rb', line 24 def sorters @sorters end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
53 54 55 56 57 58 59 60 61 |
# File 'lib/dbee/query.rb', line 53 def ==(other) other.instance_of?(self.class) && other.limit == limit && other.offset == offset && other.from == from && other.sorted_fields == sorted_fields && other.sorted_filters == sorted_filters && other.sorted_sorters == sorted_sorters end |