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.
- #row_count ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(connection, types = {}, address) ⇒ Result
Returns a new instance of Result.
55 56 57 58 59 60 61 62 |
# File 'lib/db/postgres/native/result.rb', line 55 def initialize(connection, types = {}, address) super(address) @connection = connection @fields = nil @types = types @casts = nil end |
Instance Method Details
#cast!(row) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/db/postgres/native/result.rb', line 80 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
92 93 94 95 96 97 98 |
# File 'lib/db/postgres/native/result.rb', line 92 def each row_count.times do |i| yield cast!(get_row(i)) end Native.clear(self) end |
#field_count ⇒ Object
64 65 66 |
# File 'lib/db/postgres/native/result.rb', line 64 def field_count Native.field_count(self) end |
#field_names ⇒ Object
72 73 74 |
# File 'lib/db/postgres/native/result.rb', line 72 def field_names field_count.times.collect{|i| Native.field_name(self, i)} end |
#field_types ⇒ Object
68 69 70 |
# File 'lib/db/postgres/native/result.rb', line 68 def field_types field_count.times.collect{|i| @types[Native.field_type(self, i)]} end |
#row_count ⇒ Object
76 77 78 |
# File 'lib/db/postgres/native/result.rb', line 76 def row_count Native.row_count(self) end |
#to_a ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/db/postgres/native/result.rb', line 100 def to_a rows = [] self.each do |row| rows << row end return rows end |