Class: Restforce::Query

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/restforce/query.rb,
lib/restforce/query/builder.rb,
lib/restforce/query/version.rb,
lib/restforce/query/where_renderer.rb

Overview

This is the main entry point for starting a query Chain calls to: select, where, distinct, from, group_by, limit or select_distinct to use it

Defined Under Namespace

Classes: Builder, WhereRenderer

Constant Summary collapse

VERSION =
'0.2.0'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(query_builder = Builder.new, restforce_client = Restforce.new) ⇒ Query

Returns a new instance of Query.



11
12
13
14
# File 'lib/restforce/query.rb', line 11

def initialize(query_builder = Builder.new, restforce_client = Restforce.new)
  @query_builder = query_builder
  @restforce_client = restforce_client
end

Instance Method Details

#each(&block) ⇒ Object



36
37
38
# File 'lib/restforce/query.rb', line 36

def each(&block)
  execute.each(&block)
end

#executeObject



30
31
32
33
34
# File 'lib/restforce/query.rb', line 30

def execute
  return @results unless @results.nil?
  query = @query_builder.to_s
  @results = @restforce_client.query(query)
end

#findObject



40
41
42
43
44
# File 'lib/restforce/query.rb', line 40

def find
  @query_builder.limit(1)
  execute
  @results.first
end