class

DB::ResultSet

Inherits DB::Disposable / Reference / Object

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.

Constructors

new(statement : DB::Statement)
Source

Instance methods

column_count

Returns the number of columns in the result

Source
column_name(index : Int32) : String

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

Source
column_names

Returns the name of the columns.

Source
each

Iterates over all the rows

Source
each_column

Iterates over all the columns

Source
move_next

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

Source
next_column_index

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.

Source
read(type : Enum.class)

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
Source
read(type : DB::Mappable.class)

Reads the next columns and maps them to a class

Source
read(type : T.class) : T forall T

Reads the next column value as a type

Source
read

Reads the next column value

Source
read(*types : Class)

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

Source
read

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

Source