class Dbee::Query

This class is an abstration of a simplified SQL expression. In DB terms:

Attributes

fields[R]
filters[R]
from[R]
limit[R]
sorters[R]

Public Class Methods

new( fields: [], from: nil, filters: [], limit: nil, sorters: [] ) click to toggle source
# File lib/dbee/query.rb, line 34
def initialize(
  fields: [],
  from: nil,
  filters: [],
  limit: nil,
  sorters: []
)
  @fields  = Field.array(fields)
  @filters = Filters.array(filters).uniq
  @from    = from.to_s
  @limit   = limit.to_s.empty? ? nil : limit.to_i
  @sorters = Sorters.array(sorters).uniq

  freeze
end

Public Instance Methods

==(other) click to toggle source
# File lib/dbee/query.rb, line 50
def ==(other)
  other.instance_of?(self.class) &&
    other.limit == limit &&
    other.from == from &&
    other.sorted_fields == sorted_fields &&
    other.sorted_filters == sorted_filters &&
    other.sorted_sorters == sorted_sorters
end
Also aliased as: eql?
eql?(other)
Alias for: ==
key_chain() click to toggle source
# File lib/dbee/query.rb, line 60
def key_chain
  KeyChain.new(key_paths)
end

Private Instance Methods

key_paths() click to toggle source
# File lib/dbee/query.rb, line 66
def key_paths
  (
    fields.flat_map(&:key_paths) +
    filters.map(&:key_path) +
    sorters.map(&:key_path)
  )
end