Class: NusaDB::Result
- Inherits:
-
Object
- Object
- NusaDB::Result
- Includes:
- Enumerable
- Defined in:
- lib/nusadb/connection.rb
Overview
The result of a statement: column names, rows (each an array of String/nil), and the command tag.
Instance Attribute Summary collapse
-
#column_types ⇒ Object
readonly
Returns the value of attribute column_types.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
-
#affected ⇒ Object
The affected-row count parsed from the trailing number of the command tag.
-
#each ⇒ Object
Iterate rows as hashes keyed by column name.
-
#initialize(columns, rows, command, column_types = nil) ⇒ Result
constructor
A new instance of Result.
- #to_a ⇒ Object
Constructor Details
#initialize(columns, rows, command, column_types = nil) ⇒ Result
Returns a new instance of Result.
26 27 28 29 30 31 32 33 |
# File 'lib/nusadb/connection.rb', line 26 def initialize(columns, rows, command, column_types = nil) @columns = columns @rows = rows @command = command # Per-column type name (protocol 1.1, R42-B.03), parallel to +columns+; each entry is a # canonical name such as 'INT'/'TEXT' or nil if the server did not report it. @column_types = column_types || Array.new(columns.size) end |
Instance Attribute Details
#column_types ⇒ Object (readonly)
Returns the value of attribute column_types.
24 25 26 |
# File 'lib/nusadb/connection.rb', line 24 def column_types @column_types end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
24 25 26 |
# File 'lib/nusadb/connection.rb', line 24 def columns @columns end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
24 25 26 |
# File 'lib/nusadb/connection.rb', line 24 def command @command end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
24 25 26 |
# File 'lib/nusadb/connection.rb', line 24 def rows @rows end |
Instance Method Details
#affected ⇒ Object
The affected-row count parsed from the trailing number of the command tag.
49 50 51 52 53 54 |
# File 'lib/nusadb/connection.rb', line 49 def affected return 0 if @command.nil? last = @command.split(' ').last last =~ /\A\d+\z/ ? last.to_i : 0 end |
#each ⇒ Object
Iterate rows as hashes keyed by column name.
36 37 38 39 40 41 42 |
# File 'lib/nusadb/connection.rb', line 36 def each return enum_for(:each) unless block_given? @rows.each do |row| yield @columns.each_with_index.to_h { |name, i| [name, row[i]] } end end |
#to_a ⇒ Object
44 45 46 |
# File 'lib/nusadb/connection.rb', line 44 def to_a each.to_a end |