abstract class RethinkORM::Base

Included Modules

Defined in:

rethinkdb-orm/base.cr

Constant Summary

AM_PARENT_TYPE = {:type => RethinkORM::Base} of Nil => Nil
DEFAULTS = {} of Nil => Nil
FIELDS = {id => {klass: String, converter: nil, mass_assign: true, should_persist: true, tags: {es_type: "keyword"}}} of Nil => Nil
HAS_KEYS = [true]
INDICES = [] of NamedTuple(field: String, table: String)
LOCAL_FIELDS = {id => {klass: String, converter: nil, mass_assign: true, should_persist: true, tags: {es_type: "keyword"}}} of Nil => Nil

Macro level constants

PERSIST = {id => {klass: String, converter: nil, mass_assign: true, should_persist: true, tags: {es_type: "keyword"}}} of Nil => Nil
SETTERS = {id => nil} of Nil => Nil
TABLES = [] of String

Class Method Summary

Instance Method Summary

Instance methods inherited from module RethinkORM::Persistence

delete delete, destroy destroy, destroyed destroyed, destroyed=(destroyed) destroyed=, destroyed? 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

Class Method Detail

def self.all #

Cursor of each model in the database


[View source]
def self.attributes #

You may want a list of available attributes


def self.changes(id : String | Nil = nil) #

Establishes a changefeed of models in a RethinkDB table


[View source]
def self.clear #

Removes all records from the table


[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(&predicate : RethinkDB::DatumTerm -> RethinkDB::DatumTerm) #

Returns a count of documents for which predicate block is true


[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


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

Creates the model

Raises a RethinkORM::Error::DocumentNotSaved if failed to created


[View source]
def self.exists?(id) #

Check for document presence in the table


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

Find single document by id


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

Lookup document by id

Throws if document is not present


[View source]
def self.find_all(ids, **options) #

Look up document by id


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

Returns documents with columns matching the given criteria

Could use .get_all, however this requires an index built on the queried field

TODO Implement get_all method once index functionality implemented


[View source]
def self.get_all(ids, **options) #

Query by ids, optionally set a secondary index


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

[View source]
def self.raw_changes(id : String | Nil = nil) #

Establishes a changefeed of raw JSON documents


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

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(&) #

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) #

[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 | Nil = nil) #

Process attributes must be called while constants are in scope


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

Accept HTTP params


def attributes #

Returns a Hash of all the attribute values


def attributes_tuple #

Returns a NamedTuple of all attribute values


def id_default : String | Nil #

Attribute default value


[View source]
def persistent_attributes #

Returns a hash of all attributes that may be persisted


def uuid_generator=(generator : Class) #

Allow user defined uuid generator


[View source]