Class: DB::Postgres::Native::Result
- Inherits:
-
FFI::Pointer
- Object
- FFI::Pointer
- DB::Postgres::Native::Result
- Defined in:
- lib/db/postgres/native/result.rb
Instance Method Summary collapse
- #cast!(row) ⇒ Object
- #each ⇒ Object
- #field_count ⇒ Object
- #field_names ⇒ Object
- #field_types ⇒ Object
-
#initialize(connection, types = {}, address) ⇒ Result
constructor
A new instance of Result.
- #map(&block) ⇒ Object
- #row_count ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(connection, types = {}, address) ⇒ Result
Returns a new instance of Result.
57 58 59 60 61 62 63 64 |
# File 'lib/db/postgres/native/result.rb', line 57 def initialize(connection, types = {}, address) super(address) @connection = connection @fields = nil @types = types @casts = nil end |
Instance Method Details
#cast!(row) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/db/postgres/native/result.rb', line 82 def cast!(row) @casts ||= self.field_types row.size.times do |index| if cast = @casts[index] row[index] = cast.parse(row[index]) end end return row end |
#each ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/db/postgres/native/result.rb', line 94 def each row_count.times do |i| yield cast!(get_row(i)) end Native.clear(self) end |
#field_count ⇒ Object
66 67 68 |
# File 'lib/db/postgres/native/result.rb', line 66 def field_count Native.field_count(self) end |
#field_names ⇒ Object
74 75 76 |
# File 'lib/db/postgres/native/result.rb', line 74 def field_names field_count.times.collect{|i| Native.field_name(self, i)} end |
#field_types ⇒ Object
70 71 72 |
# File 'lib/db/postgres/native/result.rb', line 70 def field_types field_count.times.collect{|i| @types[Native.field_type(self, i)]} end |
#map(&block) ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/db/postgres/native/result.rb', line 102 def map(&block) results = [] self.each do |row| results << yield(row) end return results end |
#row_count ⇒ Object
78 79 80 |
# File 'lib/db/postgres/native/result.rb', line 78 def row_count Native.row_count(self) end |
#to_a ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/db/postgres/native/result.rb', line 112 def to_a rows = [] self.each do |row| rows << row end return rows end |