Class: Dbee::Query
- Inherits:
-
Object
- Object
- Dbee::Query
- Defined in:
- lib/dbee/query.rb,
lib/dbee/query/field.rb,
lib/dbee/query/sorter.rb,
lib/dbee/query/filters.rb,
lib/dbee/query/filters/base.rb,
lib/dbee/query/filters/equals.rb,
lib/dbee/query/filters/contains.rb,
lib/dbee/query/filters/less_than.rb,
lib/dbee/query/filters/not_equals.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, NoFieldsError, Sorter
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#sorters ⇒ Object
readonly
Returns the value of attribute sorters.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#initialize(fields:, filters: [], limit: nil, sorters: []) ⇒ Query
constructor
A new instance of Query.
- #key_chain ⇒ Object
Constructor Details
#initialize(fields:, filters: [], limit: nil, sorters: []) ⇒ Query
Returns a new instance of Query.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dbee/query.rb', line 27 def initialize(fields:, filters: [], limit: nil, sorters: []) @fields = Field.array(fields) # If no fields were passed into a query then we will have no data to return. # Let's raise a hard error here and let the consumer deal with it since this may # have implications in downstream SQL generators. raise NoFieldsError if @fields.empty? @filters = Filters.array(filters) @limit = limit.to_s.empty? ? nil : limit.to_i @sorters = Sorter.array(sorters) freeze end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
25 26 27 |
# File 'lib/dbee/query.rb', line 25 def fields @fields end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
25 26 27 |
# File 'lib/dbee/query.rb', line 25 def filters @filters end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
25 26 27 |
# File 'lib/dbee/query.rb', line 25 def limit @limit end |
#sorters ⇒ Object (readonly)
Returns the value of attribute sorters.
25 26 27 |
# File 'lib/dbee/query.rb', line 25 def sorters @sorters end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
42 43 44 45 46 47 |
# File 'lib/dbee/query.rb', line 42 def ==(other) other.fields.sort == fields.sort && other.filters.sort == filters.sort && other.limit == limit && other.sorters.sort == sorters.sort end |
#key_chain ⇒ Object
50 51 52 |
# File 'lib/dbee/query.rb', line 50 def key_chain KeyChain.new(key_paths) end |