module Granite::Querying

Direct including types

Defined in:

granite/querying.cr

Instance Method Summary

Instance Method Detail

def all(clause = "", params = [] of Granite::Columns::Type) #

All will return all rows in the database. The clause allows you to specify a WHERE, JOIN, GROUP BY, ORDER BY and any other SQL92 compatible query to your table. The result will be a Collection(Model) object which lazy loads an array of instantiated instances of your Model class. This allows you to take full advantage of the database that you are using so you are not restricted or dummied down to support a DSL. Lazy load prevent running unnecessary queries from unused variables.


[View source]
def count : Int32 #

count returns a count of all the records


[View source]
def exec(clause = "") #

[View source]
def exists?(id : Number | String | Nil) : Bool #

Returns true if a records exists with a PK of id, otherwise false.


[View source]
def exists?(criteria : Granite::ModelArgs) : Bool #

Returns true if a records exists that matches criteria, otherwise false.


[View source]
def exists?(**criteria : Granite::Columns::Type) : Bool #

Returns true if a records exists that matches criteria, otherwise false.


[View source]
def find(value) #

find returns the row with the primary key specified. Otherwise nil.


[View source]
def find!(value) #

find returns the row with the primary key specified. Otherwise raises an exception.


[View source]
def find_by(criteria : Granite::ModelArgs) #

Returns the first row found that matches criteria. Otherwise nil.


[View source]
def find_by(**criteria : Granite::Columns::Type) #

Returns the first row found that matches criteria. Otherwise nil.


[View source]
def find_by!(criteria : Granite::ModelArgs) #

Returns the first row found that matches criteria. Otherwise raises a NotFound exception.


[View source]
def find_by!(**criteria : Granite::Columns::Type) #

Returns the first row found that matches criteria. Otherwise raises a NotFound exception.


[View source]
def find_each(clause = "", params = [] of Granite::Columns::Type, batch_size limit = 100, offset = 0, &) #

[View source]
def find_in_batches(clause = "", params = [] of Granite::Columns::Type, batch_size limit = 100, offset = 0, &) #

[View source]
def first(clause = "", params = [] of Granite::Columns::Type) #

First adds a LIMIT 1 clause to the query and returns the first result


[View source]
def first!(clause = "", params = [] of Granite::Columns::Type) #

[View source]
def from_rs(result : DB::ResultSet) : self #

Entrypoint for creating a new object from a result set.


[View source]
def query(clause = "", params = [] of Granite::Columns::Type, &) #

[View source]
def raw_all(clause = "", params = [] of Granite::Columns::Type) #

[View source]
def scalar(clause = "", &) #

[View source]