Module: Cassie::Statements::Execution::Fetching

Extended by:
ActiveSupport::Concern
Defined in:
lib/cassie/statements/execution/fetching.rb

Instance Method Summary collapse

Instance Method Details

#fetch(args = {}) ⇒ Object

Returns array of rows or empty array

query.fetch(id: 1)
=> [{id: 1, name: 'eprothro'}]


19
20
21
22
23
24
25
26
27
# File 'lib/cassie/statements/execution/fetching.rb', line 19

def fetch(args={})
  args.each do |k, v|
    setter = "#{k}="
    send(setter, v) if respond_to? setter
  end

  execute
  result
end

#fetch_first(args = {}) ⇒ Object

Returns first result or nil

query.fetch_first(id: 1)
=> {id: 1, name: 'eprothro'}

query.fetch_first(id: 2)
=> nil


36
37
38
39
40
# File 'lib/cassie/statements/execution/fetching.rb', line 36

def fetch_first(args={})
  with_limit(1) do
    fetch(args).first
  end
end

#fetch_first!(args = {}) ⇒ Object

Returns first result or raises RecordNotFound

query.fetch_first!(id: 1)
=> {id: 1, name: 'eprothro'}

query.fetch_first!(id: 2)
RecordNotFound: RecordNotFound


49
50
51
# File 'lib/cassie/statements/execution/fetching.rb', line 49

def fetch_first!(args={})
  fetch_first || raise(Cassie::Statements::RecordNotFound.new('CQL row does not exist'))
end