Class: DB::Postgres::Native::Result

Inherits:
FFI::Pointer
  • Object
show all
Includes:
Enumerable
Defined in:
lib/db/postgres/native/result.rb

Instance Method Summary collapse

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

#eachObject



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_countObject



68
69
70
# File 'lib/db/postgres/native/result.rb', line 68

def field_count
	Native.field_count(self)
end

#field_namesObject



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_typesObject



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_countObject



80
81
82
# File 'lib/db/postgres/native/result.rb', line 80

def row_count
	Native.row_count(self)
end