abstract class RethinkORM::Base

Included Modules

Direct Known Subclasses

Defined in:

rethinkdb-orm/base.cr

Constant Summary

AM_PARENT_TYPE = {:type => RethinkORM::Base} of Nil => Nil
INDICES = [] of NamedTuple(field: String, table: String)
TABLES = ["locks"] of String

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module RethinkORM::Persistence

_new_flag _new_flag, _new_flag=(_new_flag) _new_flag=, delete delete, destroy destroy, destroyed=(destroyed : Bool) destroyed=, destroyed? : Bool destroyed?, new_record? new_record?, persisted? persisted?, reload! reload!, save(**options) save, save!(**options) save!, update(**attributes) update, update!(**attributes) update!, update_fields(**attributes) update_fields

Instance methods inherited from module RethinkORM::Associations

reset_associations reset_associations

Constructor Detail

def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

[View source]
def self.new(pull : JSON::PullParser) #

[View source]

Class Method Detail

def self.all(**options) #

Cursor of each model in the database


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

Returns all attribute keys.


def self.changes(id : String? = nil, **options) #

Changefeed at document (if id passed) or table level

Yields an infinite iterator of model events


[View source]
def self.changes(**options, & : RethinkDB::Table -> HasChanges) #

Creates a Changefeed on query


[View source]
def self.clear #

Removes all records from the table


[View source]
def self.collection_query(**options, &) #

Unsafe method until .where can accept more generic arguments Makes 2 LARGE assumptions

  • User correctly scopes the query under the right table
  • User forms a query that returns a collection of models

Should raise/not compile on malformed query/incorrect return type to create a collection


[View source]
def self.count #

Returns a count of all documents in the table


[View source]
def self.count(**attrs) #

Returns a count of all documents in the table


[View source]
def self.count(**attrs, &predicate : RethinkDB::DatumTerm -> RethinkDB::DatumTerm) #

Returns a count of documents for which predicate block is true


[View source]
def self.create(**attributes) #

Creates the model.

Persistence can be confirmed via #persisted?


[View source]
def self.create!(**attributes) #

Creates the model.

See #save!


[View source]
def self.exists?(id : String, **options) #

Check for document presence in the table


[View source]
def self.find(id : String, **options) #

Find single document by id


[View source]
def self.find!(id : String, **options) #

Lookup document by id

Throws if document is not present


[View source]
def self.find_all(ids : Array | Tuple, **options) #

Query by ids, optionally set a secondary index


[View source]
def self.find_by(**attribute) #

Returns documents with columns matching the given criteria

DEPRECATED Use .where instead.


[View source]
def self.find_by(**attribute, &predicate : RethinkDB::DatumTerm -> RethinkDB::DatumTerm) #

Returns documents with columns matching the given criteria

DEPRECATED Use .where instead.


[View source]
def self.get_all(values : Array | Tuple, **options) #

Query by ids, optionally set a secondary index

DEPRECATED Use .find_all instead.


[View source]
def self.has_index?(field) #

[View source]
def self.raw_changes(id : String? = nil, **options) #

Establishes a changefeed of models in a RethinkDB table Changefeed at document (id passed) or table level


[View source]
def self.raw_changes(**options, & : RethinkDB::Table -> HasChanges) #

Creates a Changefeed::Raw on query


[View source]
def self.raw_query(**options, &) #

Unsafe method until .where can accept more generic arguments Makes 2 LARGE assumptions

  • User correctly scopes the query under the right table
  • User forms a query that returns a collection of models

Should raise/not compile on malformed query/incorrect return type to create a collection


[View source]
def self.table_query(**options, &) #

Yield a RethinkDB handle namespaced under the document table


[View source]
def self.where(&predicate : RethinkDB::DatumTerm -> RethinkDB::DatumTerm) #

Returns documents for which predicate block is true


[View source]
def self.where(**attrs, &predicate : RethinkDB::DatumTerm -> RethinkDB::DatumTerm) #

[View source]
def self.where(attrs : Hash, **options) #

Returns documents containing fields that match the attributes


[View source]
def self.where(**attrs) #

Returns documents containing fields that match the attributes


[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


[View source]
def apply_defaults #

Generate code to apply default values


def assign_attributes(id : String? | Missing = Missing) #

Assign to multiple attributes.


def assign_attributes(params : HTTP::Params | Hash(String, String) | Tuple(String, String)) #

Assign to mulitple attributes via HTTP::Params.


def attributes #

Returns a Hash of all attribute values


def attributes_tuple #

Returns a NamedTuple of all attribute values.


def id : String? #

Default primary key


def id=(id : String?) #

Default primary key


def id_change : Tuple(String??, String??)? #

Returns a Tuple of the previous and the current value of an instance variable if it has changed


def id_changed? : Bool #

def id_default : String? #

#id's default value


[View source]
def id_present? : Bool #

Default primary key


def id_was : String | Nil | Nil #

def id_will_change! : Nil #

Include #id in the set of changed attributes, whether it has changed or not.


def persistent_attributes #

Returns a Hash of all attributes that can be persisted.


def uuid_generator=(generator : Class) #

Allow user defined uuid generator


[View source]