module PgORM::Query

Overview

Most methods are delegated to a Collection(T) object.

Defined in:

pg-orm/query.cr
pg-orm/query/builder.cr
pg-orm/query/cache.cr
pg-orm/query/iterator.cr
pg-orm/query/methods.cr

Instance Method Summary

Instance Method Detail

def all : Collection(self) #

[View source]
def average(column_name : Symbol | String) : Float64 #

[View source]
def count(column_name : Symbol | String = "*", distinct = false) : Int64 #

[View source]
def distinct(value = true) : Collection(self) #

[View source]
def exists?(id) : Bool #

[View source]
def find(id) : self #

[View source]
def find!(id) : self #

[View source]
def find?(id) : self | Nil #

[View source]
def find_all(ids : Array) : Collection(self) #

[View source]
def find_all_by_sql(sql : String, *args_, args : Array | Nil = nil) : Array(self) #

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

[View source]
def find_by(**args) : self #

[View source]
def find_by?(**args) : self | Nil #

[View source]
def find_one_by_sql(sql : String, *args_, args : Array | Nil = nil) : self #

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.


[View source]
def find_one_by_sql?(sql : String, *args_, args : Array | Nil = nil) : self | Nil #

Same as #find_one_by_sql but returns nil when no record could be found in the database.


[View source]
def first : self #

[View source]
def first? : self | Nil #

[View source]
def group_by(*columns : Symbol | String) : Collection(self) #

[View source]
def ids : Array #

[View source]
def join(type : JoinType, model : Base.class, fk : Symbol, pk : Base.class | Nil = nil) : Collection(self) #

[View source]
def join(type : JoinType, model : Base.class, on : String) : Collection(self) #

[View source]
def last : self #

[View source]
def last? : self | Nil #

[View source]
def limit(value : Int32) : Collection(self) #

[View source]
def maximum(column_name : Symbol | String) #

[View source]
def minimum(column_name : Symbol | String) #

[View source]
def none : Collection(self) #

[View source]
def offset(value : Int32) : Collection(self) #

[View source]
def order(columns : Hash(Symbol, Symbol)) : Collection(self) #

[View source]
def order(*columns : Symbol | String) : Collection(self) #

[View source]
def order(**columns) : Collection(self) #

[View source]
def pluck(column_name : Symbol | String) : Array(Value) #

[View source]
def reorder(columns : Hash(Symbol, Symbol)) : Collection(self) #

[View source]
def reorder(*columns : Symbol | String) : Collection(self) #

[View source]
def reorder(**columns) : Collection(self) #

[View source]
def select(sql : String) : Collection(self) #

[View source]
def select(*columns : Symbol) : Collection(self) #

[View source]
def sum(column_name : Symbol | String) : Int64 | Float64 #

[View source]
def take : self #

[View source]
def take? : self | Nil #

[View source]
def where(sql : String) : Collection(self) #

[View source]
def where(conditions : Hash(Symbol, Value | Array(Value)) | NamedTuple) : Collection(self) #

[View source]
def where(sql : String, *args : Value) : Collection(self) #

[View source]
def where(**conditions) : Collection(self) #

[View source]
def where_not(conditions : Hash(Symbol, Value | Array(Value)) | NamedTuple) : Collection(self) #

[View source]
def where_not(**conditions) : Collection(self) #

[View source]