class

RethinkORM::Base

Inherits RethinkORM::Validators / RethinkORM::Table / RethinkORM::Queries / RethinkORM::Persistence / RethinkORM::Index / RethinkORM::Associations / ActiveModel::Callbacks / ActiveModel::Validation / ActiveModel::Model / DB::Mappable / DB::Serializable / YAML::Serializable / JSON::Serializable / Reference / Object

Constants

AM_PARENT_TYPE = {:type => RethinkORM::Base} of Nil => Nil
CALLBACKS = { before_save: [] of Nil, after_save: [] of Nil, before_create: [] of Nil, after_create: [] of Nil, before_update: [] of Nil, after_update: [] of Nil, before_destroy: [] of Nil, after_destroy: [] of Nil, }
INDICES = [] of NamedTuple(field: String, table: String)
TABLES = ["locks"] of String

Constructors

new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
Source
new(pull : JSON::PullParser)
Source
new(rs : DB::ResultSet)
Source

Class methods

all

Cursor of each model in the database

Source
attributes

Returns all attribute keys.

changes(id : String | Nil = nil, **options)

Changefeed at document (if id passed) or table level

Yields an infinite iterator of model events

Source
changes

Creates a Changefeed on query

Source
clear

Removes all records from the table

Source
collection_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

Source
count

Returns a count of all documents in the table

Source
count

Returns a count of all documents in the table

Source
count

Returns a count of documents for which predicate block is true

Source
create

Creates the model.

Persistence can be confirmed via #persisted?

Source
create!

Creates the model.

See #save!

Source
exists?(id : String, **options)

Check for document presence in the table

Source
find(id : String, **options)

Find single document by id

Source
find!(id : String, **options)

Lookup document by id

Throws if document is not present

Source
find_all(ids : Array | Tuple, **options)

Query by ids, optionally set a secondary index

Source
find_by

Returns documents with columns matching the given criteria

Source
find_by

Returns documents with columns matching the given criteria

Source
from_rs(rs : DB::ResultSet)
Source
get_all(values : Array | Tuple, **options)

Query by ids, optionally set a secondary index

Source
has_index?(field)
Source
raw_changes(id : String | Nil = nil, **options)

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

Source
raw_changes

Creates a Changefeed::Raw on query

Source
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

Source
table_query

Yield a RethinkDB handle namespaced under the document table

Source
where

Returns documents for which predicate block is true

Source
where
Source
where(attrs : Hash, **options)

Returns documents containing fields that match the attributes

Source
where

Returns documents containing fields that match the attributes

Source

Instance methods

==(other : self)

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

Source
after_create
after_destroy
after_save
after_update
apply_defaults

Generate code to apply default values

assign_attributes(id : String | Nil | Missing = Missing)

Assign to multiple attributes.

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

Assign to multiple attributes via HTTP::Params.

assign_attributes(model : RethinkORM::Base)

Assign to multiple attributes from a model object

attributes

Returns a Hash of all attribute values

attributes_tuple

Returns a NamedTuple of all attribute values.

before_create
before_destroy
before_save
before_update
id

NOTE: use getter / getter! (not property / property!) so that the setter defined later in __create_initializer__ is the only setter on the field. Crystal's overload resolution silently fails to replace a property-defined setter with one of identical signature for generic types (e.g. Set(String)?, Array(String)?, String | Array(String)), although it does work for non-generic ones like String?. Defining the setter only once via __create_initializer__ ensures change tracking, sanitization, and custom setter blocks run uniformly across all types.

id_assigned?
id_change

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

id_changed?
id_default

id's default value

Source
id_present?

Default primary key

id_removed?
id_was
id_will_change!

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

persistent_attributes

Returns a Hash of all attributes that can be persisted.

run_create_callbacks

Wrap a block with callbacks for the appropriate crud operation.

Defined once here rather than once per subclass, and reached through the before_*/after_* methods rather than by expanding __before_* inline.

These methods yield, and Crystal cannot dispatch a yielding method through a pointer -- it inlines the body at each call site. Defining them per subclass therefore meant that a run_*_callbacks call on an abstract receiver emitted one inlined copy per concrete subclass, each containing a type-id dispatch chain for every self call in the block. Nesting two of them (run_update_callbacks { run_save_callbacks { ... } }) made that quadratic in the number of models.

With a single definition there is one inlined copy, and before_* / after_* are ordinary non-yielding overrides that share one dispatch wrapper.

Source
run_destroy_callbacks
Source
run_save_callbacks
Source
run_update_callbacks
Source
uuid_generator=(generator : Class)

Allow user defined uuid generator

Source