abstract class DB::ResultSet

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

  1. Override #move_next to move to the next row.
  2. Override #read returning the next value in the row.
  3. (Optional) Override #read(t) for some types t for which custom logic other than a simple cast is needed.
  4. Override #column_count, #column_name.

Included Modules

Defined in:

db/result_set.cr

Constructors

Instance Method Summary

Instance methods inherited from module DB::Disposable

close close, closed? closed?

Constructor Detail

def self.new(statement : DB::Statement) #

[View source]

Instance Method Detail

abstract def column_count : Int32 #

Returns the number of columns in the result


[View source]
abstract def column_name(index : Int32) : String #

Returns the name of the column in index 0-based position.


[View source]
def column_names #

Returns the name of the columns.


[View source]
def each(&) #

Iterates over all the rows


[View source]
def each_column(&) #

Iterates over all the columns


[View source]
abstract def move_next : Bool #

Move the next row in the result. Return false if no more rows are available. See #each


[View source]
def read(type : DB::Mappable.class) #

Reads the next columns and maps them to a class


[View source]
def read(type : T.class) : T forall T #

Reads the next column value as a type


[View source]
abstract def read #

Reads the next column value


[View source]
def read(*types : Class) #

Reads the next columns and returns a tuple of the values.


[View source]
def read(**types : Class) #

Reads the next columns and returns a named tuple of the values.


[View source]