class Marten::DB::Query::RawSet(M)
- Marten::DB::Query::RawSet(M)
- Reference
- Object
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
- Enumerable(M)
Defined in:
marten/db/query/raw_set.crConstructors
- .new(query : String, params : Array(::DB::Any) | Hash(String, ::DB::Any), using : String | Nil)
- .new(query : Marten::DB::Query::SQL::RawQuery(M) = SQL::RawQuery(M).new)
Instance Method Summary
-
#[](index : Int)
Returns the record at the given index.
-
#[](range : Range)
Returns the records corresponding to the passed range.
-
#[]?(index : Int)
Returns the record at the given index.
-
#[]?(range : Range)
Returns the records corresponding to the passed range.
-
#count
Returns the number of records that are targeted by the current raw query set.
-
#each(&)
Allows to iterate over the records that are targeted by the current query set.
-
#size
Returns the number of records that are targeted by the current raw query set.
-
#using(db : String | Symbol)
Allows to define which database alias should be used when evaluating the raw query set.
Constructor Detail
Instance Method Detail
Returns the record at the given index.
If no record can be found at the given index, then an IndexError
exception is raised.
Returns the records corresponding to the passed range.
If no records match the passed range, an IndexError
exception is raised.
Returns the record at the given index.
nil
is returned if no record can be found at the given index.
Returns the records corresponding to the passed range.
nil
is returned if no records match the passed range.
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
Allows to define which database alias should be used when evaluating the raw query set.