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

Inherits:
FFI::Pointer
  • Object
show all
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.



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

#eachObject



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_countObject



64
65
66
# File 'lib/db/postgres/native/result.rb', line 64

def field_count
	Native.field_count(self)
end

#field_namesObject



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_typesObject



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_countObject



76
77
78
# File 'lib/db/postgres/native/result.rb', line 76

def row_count
	Native.row_count(self)
end

#to_aObject



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