module Avram::Queryable(T)

Included Modules

Defined in:

avram/queryable.cr

Instance Method Summary

Instance Method Detail

def add_preload(&block : Array(T) -> Nil) #

[View source]
def any? : Bool #
Description copied from module Enumerable(T)

Returns true if at least one of the collection's members is truthy.

[nil, true, 99].any? # => true
[nil, false].any?    # => false

[View source]
def cache_key(operation : Symbol) : String #

[View source]
def cache_key : String #

[View source]
def cache_store #

[View source]
def database(*args, **options) #

[View source]
def database(*args, **options, &) #

[View source]
def delete : Int64 #

Delete the records using the query's where clauses, or all records if no wheres are added.

Returns the number of deleted records as Int64.

# DELETE FROM users WHERE age < 21
UserQuery.new.age.lt(21).delete

[View source]
def distinct : self #

[View source]
def distinct_on(&) : self #

[View source]
def each(&) #
Description copied from module Enumerable(T)

Must yield this collection's elements to the block.


[View source]
def exec_scalar(&) #

[View source]
def first #
Description copied from module Enumerable(T)

Returns the first element in the collection. Raises Enumerable::EmptyError if the collection is empty.

([1, 2, 3]).first   # => 1
([] of Int32).first # raises Enumerable::EmptyError

[View source]
def first? #
Description copied from module Enumerable(T)

Returns the first element in the collection. When the collection is empty, returns nil.

([1, 2, 3]).first?   # => 1
([] of Int32).first? # => nil

[View source]
def group(&) : self #

[View source]
def group_count : Hash(Array(PGValue), Int64) #

[View source]
def join(join_clause : Avram::Join::SqlClause) : self #

[View source]
def last #

[View source]
def last? #

[View source]
def limit(amount) : self #

[View source]
def merge_query(query_to_merge : Avram::QueryBuilder) : self #

[View source]
def none : self #

[View source]
def none? : Bool #
Description copied from module Enumerable(T)

Returns true if all of the elements of the collection are falsey.

[nil, false].none?       # => true
[nil, false, true].none? # => false

It's the opposite of all?.


[View source]
def offset(amount) : self #

[View source]
def or(&) : self #

Run the #or block first to grab the last WHERE clause and set its conjunction to OR. Then call yield to set the next set of ORs


[View source]
def order_by(column, direction) : self #

[View source]
def order_by(order : Avram::OrderByClause) : self #

[View source]
def preloads #

[View source]
def primary_key_name(*args, **options) #

[View source]
def primary_key_name(*args, **options, &) #

[View source]
def query : Avram::QueryBuilder #

[View source]
def query=(query : Avram::QueryBuilder) #

[View source]
def random_order : self #

[View source]
def reset_limit : self #

[View source]
def reset_offset : self #

[View source]
def reset_order : self #

[View source]
def reset_where(&) : self #

[View source]
def results : Array(T) #

[View source]
def schema_class : T.class #

[View source]
def select_count : Int64 #

[View source]
def table_name(*args, **options) #

[View source]
def table_name(*args, **options, &) #

[View source]
def to_prepared_sql #

[View source]
def to_sql #

[View source]
abstract def update : Int64 #

Update the records using the query's where clauses, or all records if no wheres are added.

Returns the number of records updated as Int64.

# Update all comments with the word "spam" as spam
CommentQuery.new.body.ilike("spam").update(spam: true)

[View source]
def where(column : Symbol, value) : self #

[View source]
def where(sql_clause : Avram::Where::SqlClause) : self #

[View source]
def where(statement : String, *bind_vars) : self #

[View source]
def where(statement : String, *, args bind_vars : Array) : self #

[View source]
def where(&) : self #

[View source]