class Records
A buffer of records.
Definitions
def self.wrap(result)
Wrap a database result into a Records instance.
Signature
-
parameter
result
Object
The database result object with field_count, field_names, and to_a methods.
-
returns
Records, Nil
A Records instance or nil if there are no columns.
Implementation
def self.wrap(result)
# We want to avoid extra memory allocations when there are no columns:
if result.field_count == 0
return nil
end
return self.new(result.field_names, result.to_a)
end
def initialize(columns, rows)
Initialize a new Records instance with columns and rows.
Signature
-
parameter
columns
Array
Array of column names.
-
parameter
rows
Array
Array of row data.
Implementation
def initialize(columns, rows)
@columns = columns
@rows = rows
end
def freeze
Freeze the Records instance and its internal data structures.
Signature
-
returns
Records
The frozen Records instance.
Implementation
def freeze
return self if frozen?
@columns.freeze
@rows.freeze
super
end
def to_a
Get the rows as an array.
Signature
-
returns
Array
The array of row data.
Implementation
def to_a
@rows
end