module Rome::Query
Overview
Most methods are delegated to a Collection(T)
object.
Defined in:
query.crquery/builder.cr
query/cache.cr
query/iterator.cr
query/methods.cr
Instance Method Summary
- #all : Collection(self)
- #average(column_name : Symbol | String) : Float64
- #count(column_name : Symbol | String = "*", distinct = false) : Int64
- #distinct(value = true) : Collection(self)
- #exists?(id) : Bool
- #find(id) : self
- #find?(id) : self | Nil
-
#find_all_by_sql(sql : String, *args) : Array(self)
Loads records by raw SQL query.
- #find_by(**args) : self
- #find_by?(**args) : self | Nil
-
#find_one_by_sql(sql : String, *args) : self
Loads one record by raw SQL query.
-
#find_one_by_sql?(sql : String, *args) : self | Nil
Same as
#find_one_by_sql
but returnsnil
when no record could be found in the database. - #first : self
- #first? : self | Nil
- #ids : Array
- #last : self
- #last? : self | Nil
- #limit(value : Int32) : Collection(self)
- #maximum(column_name : Symbol | String)
- #minimum(column_name : Symbol | String)
- #none : Collection(self)
- #offset(value : Int32) : Collection(self)
- #order(columns : Hash(Symbol, Symbol)) : Collection(self)
- #order(*columns : Symbol | String) : Collection(self)
- #order(**columns) : Collection(self)
- #pluck(column_name : Symbol | String) : Array(Value)
- #reorder(columns : Hash(Symbol, Symbol)) : Collection(self)
- #reorder(*columns : Symbol | String) : Collection(self)
- #reorder(**columns) : Collection(self)
- #select(sql : String) : Collection(self)
- #select(*columns : Symbol) : Collection(self)
- #sum(column_name : Symbol | String) : Int64 | Float64
- #take : self
- #take? : self | Nil
- #where(conditions : Hash(Symbol, Value | Array(Value)) | NamedTuple) : Collection(self)
- #where(sql : String, *args : Value) : Collection(self)
- #where(**conditions) : Collection(self)
- #where_not(conditions : Hash(Symbol, Value | Array(Value)) | NamedTuple) : Collection(self)
- #where_not(**conditions) : Collection(self)
Instance Method Detail
def find_all_by_sql(sql : String, *args) : Array(self)
#
Loads records by raw SQL query. You may refer to arguments with ?
in the
SQL query, and pass them to the method. For example:
users = User.find_all_by_sql(<<-SQL, "julien")
SELECT * FROM "users" WHERE username = ?
SQL
def find_one_by_sql(sql : String, *args) : self
#
Loads one record by raw SQL query. You may refer to arguments with ?
in
the SQL query, and pass them to the method. For example:
user = User.find_one_by_sql(<<-SQL, "julien")
SELECT * FROM "users" WHERE username = ? LIMIT 1
SQL
Raises a RecordNotFound
exception when no record could be found in the
database.
def find_one_by_sql?(sql : String, *args) : self | Nil
#
Same as #find_one_by_sql
but returns nil
when no record could be found
in the database.