class

Marten::DB::Query::RawSet(M)

Inherits Enumerable / Reference / Object

Represents a raw query set.

A raw query set allows to easily map the results of a raw SQL statement into corresponding model instances and allows to iterate over them (like a regular query set).

Constructors

new(query : String, params : Array(::DB::Any) | Hash(String, ::DB::Any), using : String | Nil)
Source
new(query : Marten::DB::Query::SQL::RawQuery(M) = SQL::RawQuery(M).new)
Source

Instance methods

[](index : Int)

Returns the record at the given index.

If no record can be found at the given index, then an IndexError exception is raised.

Source
[](range : Range)

Returns the records corresponding to the passed range.

If no records match the passed range, an IndexError exception is raised.

Source
[]?(index : Int)

Returns the record at the given index.

nil is returned if no record can be found at the given index.

Source
[]?(range : Range)

Returns the records corresponding to the passed range.

nil is returned if no records match the passed range.

Source
count

Returns the number of records that are targeted by the current raw query set.

Source
each

Allows to iterate over the records that are targeted by the current query set.

This method can be used to define a block that iterates over the records that are targeted by a query set:

Post.all.each do |post|
  # Do something
end
Source
size

Returns the number of records that are targeted by the current raw query set.

Source
using(db : Nil | String | Symbol)

Allows to define which database alias should be used when evaluating the raw query set.

Source