Class: NativeQuery::Result
- Inherits:
-
Object
- Object
- NativeQuery::Result
- Defined in:
- lib/native-query/result.rb
Overview
Represents ORM query result.
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
-
#all ⇒ Object
Returns all rows.
-
#assoc(*args, &block) ⇒ Object
Returns data in complex associative level.
-
#count ⇒ Object
Returns count of the records.
-
#each ⇒ Object
Iterates through result.
-
#free! ⇒ Object
Frees result resources.
-
#initialize(query) ⇒ Result
constructor
Constructor.
-
#map(&block) ⇒ Object
Maps callback to array.
-
#one ⇒ Object
Returns one result row.
-
#single ⇒ Object
Returns first field value of first record.
Constructor Details
#initialize(query) ⇒ Result
Constructor.
23 24 25 |
# File 'lib/native-query/result.rb', line 23 def initialize(query) @query = query end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
17 18 19 |
# File 'lib/native-query/result.rb', line 17 def query @query end |
Instance Method Details
#all ⇒ Object
Returns all rows.
59 60 61 |
# File 'lib/native-query/result.rb', line 59 def all self.map { |row| row } end |
#assoc(*args, &block) ⇒ Object
Returns data in complex associative level.
According to limitations of equivalent MP::Fluent method. Block is applied to all resultant rows.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/native-query/result.rb', line 70 def assoc(*args, &block) @query.assoc(*args) do |row| result = Row::new(row) if block result = block.call(result) end result # returns end end |
#count ⇒ Object
Returns count of the records.
86 87 88 |
# File 'lib/native-query/result.rb', line 86 def count @query.count end |
#each ⇒ Object
Iterates through result.
47 48 49 50 51 52 53 |
# File 'lib/native-query/result.rb', line 47 def each @query.each do |row| yield Row::new(row) end self.free! end |
#free! ⇒ Object
Frees result resources.
108 109 110 |
# File 'lib/native-query/result.rb', line 108 def free! @query.free! end |
#map(&block) ⇒ Object
Maps callback to array.
94 95 96 97 98 99 100 101 102 |
# File 'lib/native-query/result.rb', line 94 def map(&block) result = [ ] self.each do |item| result << block.call(item) end return result end |
#one ⇒ Object
Returns one result row.
39 40 41 |
# File 'lib/native-query/result.rb', line 39 def one Row::new(@query.one) end |
#single ⇒ Object
Returns first field value of first record.
31 32 33 |
# File 'lib/native-query/result.rb', line 31 def single @query.single end |