class Crecto::Repo::Query

Overview

Queries are used to retrieve and manipulate data from a repository. Syntax is much like that of ActiveRecord:

Query.select('id').where(name: "fred").join(:posts).order_by("users.name").limit(1).offset(4)

Defined in:

crecto/repo/query.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.distinct(dist : String) #

Adds DISTINCT to the query

Query.distinct("users.name")

[View source]
def self.group_by(gb : String) #

Query GROUP BY

Query.where(name: "Bill").join(:posts).group_by("users.id")

[View source]
def self.join(join_association : Symbol) #

Join query with join_association

Query.join(:posts)

[View source]
def self.join(join_associations : Array(Symbol)) #

Join query with join_associations

Query.join([:posts, :projects])

[View source]
def self.limit(lim : Int32 | Int64) #

Query LIMIT

Query.limit(50)

[View source]
def self.new #

[View source]
def self.offset(off : Int32 | Int64) #

Query OFFSET

Query.offset(20)

[View source]
def self.or_where #

Key => Value pair(s) used in query OR WHERE

Query.where(name: "Thor", age: 60)

[View source]
def self.order_by(order : String) #

Field to ORDER BY

Query.order_by("last_name ASC")

[View source]
def self.preload(preload_associations : Array(Symbol)) #

Preload associations

Query.preload([:posts, :projects])

[View source]
def self.preload(preload_association : Symbol) #

Preload associations

Query.preload(:posts)

[View source]
def self.select(selects : Array(String)) #

Fields to select, separated by comma. Default is "*"

Query.select(["id", "name"])

[View source]
def self.where(where_sym : Symbol, params : Array(DbValue | PkeyValue)) #

Query WHERE IN with a Symbol and Array(DbValue)

Query.where(:name, ["Conan", "Zeus"])

[View source]
def self.where(where_string : String, param : DbValue | PkeyValue) #

Query WHERE with a String and String parameter

Query.where("name LIKE ?", "%phyllis%")

[View source]
def self.where(where_string : String) #

Query WHERE with a String

Query.where("name IS NOT NULL")

[View source]
def self.where #

Key => Value pair(s) used in query WHERE

Query.where(name: "Thor", age: 60)

[View source]
def self.where(where_sym : Symbol, param : DbValue) #

Query WHERE with a Symbol and DbValue

Query.where(:name, "Conan")

[View source]
def self.where(where_string : String, params : Array(DbValue | PkeyValue)) #

Query WHERE with a string

Query.where("users.id > ?", [10])

[View source]

Instance Method Detail

def distinct(dist : String) #

Adds DISTINCT to the query

Query.distinct("users.name")

[View source]
def distincts : String? #

[View source]
def distincts=(distincts : String?) #

[View source]
def group_by(gb : String) #

Query GROUP BY

Query.where(name: "Bill").join(:posts).group_by("users.id")

[View source]
def group_bys : String? #

[View source]
def group_bys=(group_bys : String?) #

[View source]
def join(join_association : Symbol) #

Join query with join_association

Query.join(:posts)

[View source]
def join(join_associations : Array(Symbol)) #

Join query with join_associations

Query.join([:posts, :projects])

[View source]
def joins : Array(Symbol) #

[View source]
def joins=(joins) #

[View source]
def limit : Int32? #

[View source]
def limit(lim) #

Query LIMIT

Query.limit(50)

[View source]
def limit=(limit : Int32?) #

[View source]
def offset : Int32? #

[View source]
def offset(off) #

Query OFFSET

Query.offset(20)

[View source]
def offset=(offset : Int32?) #

[View source]
def or_where #

Key => Value pair(s) used in query OR WHERE

Query.where(name: "Thor", age: 60)

[View source]
def or_wheres : Array(Hash(Symbol, Array(Bool | Float32 | Float64 | Int16 | Int32 | Int64 | JSON::Any | String | Time | Nil)) | Hash(Symbol, Array(Int32 | Int64 | Nil)) | Hash(Symbol, Array(Int32)) | Hash(Symbol, Array(Int64)) | Hash(Symbol, Array(String)) | Hash(Symbol, Bool | Float32 | Float64 | Int16 | Int32 | Int64 | JSON::Any | String | Time | Nil) | Hash(Symbol, Int32 | Int64 | Nil) | Hash(Symbol, Int32 | Int64 | String | Nil) | Hash(Symbol, Int32 | Int64 | String) | Hash(Symbol, Int32 | String) | Hash(Symbol, Int32) | Hash(Symbol, Int64 | String) | Hash(Symbol, Int64) | Hash(Symbol, Nil) | Hash(Symbol, String) | {clause: String, params: Array(Bool | Float32 | Float64 | Int16 | Int32 | Int64 | JSON::Any | String | Time | Nil)}) #

[View source]
def or_wheres=(or_wheres) #

[View source]
def order_by(order) #

Field to ORDER BY

Query.order_by("last_name ASC")

[View source]
def order_bys : Array(String) #

[View source]
def order_bys=(order_bys) #

[View source]
def preload(preload_association : Symbol) #

Preload assoication

Query.preload(:posts)

[View source]
def preload(preload_associations : Array(Symbol)) #

Preload assoications

Query.preload([:posts, :projects])

[View source]
def preloads : Array(Symbol) #

[View source]
def preloads=(preloads) #

[View source]
def select(selects : Array(String)) #

Fields to select, separated by comma. Default is "*"

Query.select([

[View source]
def selects : Array(String) #

[View source]
def selects=(selects : Array(String)) #

[View source]
def where #

Key => Value pair(s) used in query WHERE

Query.where(name: "Thor", age: 60)

[View source]
def where(where_string : String) #

Query WHERE with a String

Query.where("name IS NOT NULL")

[View source]
def where(where_string : String, param : DbValue | PkeyValue) #

Query WHERE with a String and String parameter

Query.where("name LIKE ?", "%phyllis%")

[View source]
def where(where_sym : Symbol, params : Array(DbValue)) #

Query WHERE IN with a Symbol and Array(DbValue)

Query.where(:name, ["Conan", "Zeus"])

[View source]
def where(where_sym : Symbol, param : DbValue) #

Query WHERE with a Symbol and DbValue

Query.where(:name, "Conan")

[View source]
def where(where_string : String, params : Array(DbValue)) #

Query where with a string

Query.where("users.id > ?", [10])

[View source]
def wheres : Array(Hash(Symbol, Array(Bool | Float32 | Float64 | Int16 | Int32 | Int64 | JSON::Any | String | Time | Nil)) | Hash(Symbol, Array(Int32 | Int64 | Nil)) | Hash(Symbol, Array(Int32)) | Hash(Symbol, Array(Int64)) | Hash(Symbol, Array(String)) | Hash(Symbol, Bool | Float32 | Float64 | Int16 | Int32 | Int64 | JSON::Any | String | Time | Nil) | Hash(Symbol, Int32 | Int64 | Nil) | Hash(Symbol, Int32 | Int64 | String | Nil) | Hash(Symbol, Int32 | Int64 | String) | Hash(Symbol, Int32 | String) | Hash(Symbol, Int32) | Hash(Symbol, Int64 | String) | Hash(Symbol, Int64) | Hash(Symbol, Nil) | Hash(Symbol, String) | {clause: String, params: Array(Bool | Float32 | Float64 | Int16 | Int32 | Int64 | JSON::Any | String | Time | Nil)}) #

[View source]
def wheres=(wheres) #

[View source]