Class: DB::Postgres::Native::Result
- Inherits:
-
FFI::Pointer
- Object
- FFI::Pointer
- DB::Postgres::Native::Result
- Includes:
- Enumerable
- 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
Constructor Details
#initialize(connection, types = {}, address) ⇒ Result
Returns a new instance of Result.
59 60 61 62 63 64 65 66 |
# File 'lib/db/postgres/native/result.rb', line 59 def initialize(connection, types = {}, address) super(address) @connection = connection @fields = nil @types = types @casts = nil end |
Instance Method Details
#cast!(row) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/db/postgres/native/result.rb', line 84 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
96 97 98 99 100 101 102 |
# File 'lib/db/postgres/native/result.rb', line 96 def each row_count.times do |i| yield cast!(get_row(i)) end Native.clear(self) end |
#field_count ⇒ Object
68 69 70 |
# File 'lib/db/postgres/native/result.rb', line 68 def field_count Native.field_count(self) end |
#field_names ⇒ Object
76 77 78 |
# File 'lib/db/postgres/native/result.rb', line 76 def field_names field_count.times.collect{|i| Native.field_name(self, i)} end |
#field_types ⇒ Object
72 73 74 |
# File 'lib/db/postgres/native/result.rb', line 72 def field_types field_count.times.collect{|i| @types[Native.field_type(self, i)]} end |
#row_count ⇒ Object
80 81 82 |
# File 'lib/db/postgres/native/result.rb', line 80 def row_count Native.row_count(self) end |