abstract class DB::ResultSet
- DB::ResultSet
- Reference
- Object
Overview
The response of a query performed on a Database.
See DB for a complete sample.
Each #read call consumes the result and moves to the next column.
Each column must be read in order.
At any moment a #move_next can be invoked, meaning to skip the
remaining, or even all the columns, in the current row.
Also it is not mandatory to consume the whole ResultSet, hence an iteration
through #each or #move_next can be stopped.
Note: depending on how the ResultSet was obtained it might be mandatory an
explicit call to #close. Check QueryMethods#query.
Note to implementors
- Override
#move_nextto move to the next row. - Override
#readreturning the next value in the row. - (Optional) Override
#read(t)for some typestfor which custom logic other than a simple cast is needed. - Override
#column_count,#column_name.
Included Modules
Defined in:
db/result_set.crConstructors
Instance Method Summary
-
#column_count : Int32
Returns the number of columns in the result
-
#column_name(index : Int32) : String
Returns the name of the column in
index0-based position. -
#column_names
Returns the name of the columns.
-
#each(&)
Iterates over all the rows
-
#each_column(&)
Iterates over all the columns
-
#move_next : Bool
Move the next row in the result.
-
#next_column_index : Int32
Returns the column index that corresponds to the next
#read. -
#read(type : Enum.class)
Read the value based on the given
enumtype, supporting both string and numeric column types. -
#read(type : DB::Mappable.class)
Reads the next columns and maps them to a class
-
#read(type : T.class) : T forall T
Reads the next column value as a type
-
#read
Reads the next column value
-
#read(*types : Class)
Reads the next columns and returns a tuple of the values.
-
#read(**types : Class)
Reads the next columns and returns a named tuple of the values.
Constructor Detail
Instance Method Detail
Returns the name of the column in index 0-based position.
Move the next row in the result.
Return false if no more rows are available.
See #each
Returns the column index that corresponds to the next #read.
If the last column of the current row has been read, it must return #column_count.
Read the value based on the given enum type, supporting both string and
numeric column types.
enum Status
Pending
Complete
end
db.query "SELECT 'complete'" do |rs|
rs.read Status # => Status::Complete
end