module PgORM::Query
Overview
Most methods are delegated to a Collection(T)
object.
Defined in:
pg-orm/query.crpg-orm/query/builder.cr
pg-orm/query/cache.cr
pg-orm/query/iterator.cr
pg-orm/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
- #find?(id) : self | Nil
- #find_all(ids : Array) : Collection(self)
-
#find_all_by_sql(sql : String, *args_, args : Array | Nil = nil) : Array(self)
Loads records by raw SQL query.
- #find_by(**args) : self
- #find_by?(**args) : self | Nil
-
#find_one_by_sql(sql : String, *args_, args : Array | Nil = nil) : self
Loads one record by raw SQL query.
-
#find_one_by_sql?(sql : String, *args_, args : Array | Nil = nil) : self | Nil
Same as
#find_one_by_sql
but returnsnil
when no record could be found in the database. - #first : self
- #first? : self | Nil
- #group_by(*columns : Symbol | String) : Collection(self)
- #ids : Array
- #join(type : JoinType, model : Base.class, fk : Symbol, pk : Base.class | Nil = nil) : Collection(self)
- #join(type : JoinType, model : Base.class, on : String) : Collection(self)
- #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(sql : String) : Collection(self)
- #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
Loads records by raw SQL query. You may refer to arguments with $x
where x
is the number in the
SQL query, and pass them to the method. For example:
users = User.find_all_by_sql(<<-SQL, "user")
SELECT * FROM "users" WHERE username = $0
SQL
Loads one record by raw SQL query. You may refer to arguments with $x
where x
is the number in
the SQL query, and pass them to the method. For example:
user = User.find_one_by_sql(<<-SQL, "user")
SELECT * FROM "users" WHERE username = $0 LIMIT 1
SQL
Raises a Error::RecordNotFound
exception when no record could be found in the
database.
Same as #find_one_by_sql
but returns nil
when no record could be found
in the database.
def join(type : JoinType, model : Base.class, fk : Symbol, pk : Base.class | Nil = nil) : Collection(self)
#