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

Overview

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).

Included Modules

Defined in:

marten/db/query/raw_set.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(query : String, params : Array(::DB::Any) | Hash(String, ::DB::Any), using : String | Nil) #

[View source]
def self.new(query : Marten::DB::Query::SQL::RawQuery(M) = SQL::RawQuery(M).new) #

[View source]

Instance Method Detail

def [](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.


[View source]
def [](range : Range) #

Returns the records corresponding to the passed range.

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


[View source]
def []?(index : Int) #

Returns the record at the given index.

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


[View source]
def []?(range : Range) #

Returns the records corresponding to the passed range.

nil is returned if no records match the passed range.


[View source]
def count #

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


[View source]
def 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

[View source]
def size #

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


[View source]
def using(db : String | Symbol) #

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


[View source]