abstract class Granite::Base

Overview

Granite::Base is the base class for your model objects.

Included Modules

Extended Modules

Defined in:

granite/base.cr

Class Method Summary

Instance Method Summary

Macros inherited from module Granite::ConnectionManagement

connection(name) connection

Instance methods inherited from module Granite::Querying

reload reload

Macros inherited from module Granite::Select

select_statement(text) select_statement

Macros inherited from module Granite::ValidationHelpers

validate_exclusion(field, excluded_values) validate_exclusion, validate_greater_than(field, amount, or_equal_to = false) validate_greater_than, validate_is_blank(field) validate_is_blank, validate_is_nil(field) validate_is_nil, validate_is_valid_choice(field, choices) validate_is_valid_choice, validate_less_than(field, amount, or_equal_to = false) validate_less_than, validate_max_length(field, length) validate_max_length, validate_min_length(field, length) validate_min_length, validate_not_blank(field) validate_not_blank, validate_not_nil(field) validate_not_nil, validate_uniqueness(field) validate_uniqueness

Instance methods inherited from module Granite::Validators

errors errors, valid? valid?

Instance methods inherited from module Granite::Transactions

destroy destroy, destroy! destroy!, save(*, validate : Bool = true, skip_timestamps : Bool = false) save, save!(*, validate : Bool = true, skip_timestamps : Bool = false) save!, set_timestamps(*, to time = Time.local(Granite.settings.default_timezone), mode = :create) set_timestamps, touch(*fields) : Bool touch, update(args, skip_timestamps : Bool = false)
update(**args)
update
, update!(args, skip_timestamps : Bool = false)
update!(**args)
update!

Macros inherited from module Granite::Tables

table(name) table

Instance methods inherited from module Granite::Columns

content_values : Array(Granite::Columns::Type) content_values, from_rs(result : DB::ResultSet) : Nil from_rs, primary_key_value primary_key_value, read_attribute(attribute_name : Symbol | String) : Type read_attribute, set_attributes(hash : Hash(String | Symbol, T)) : self forall T set_attributes, to_h to_h

Macros inherited from module Granite::Columns

column(decl, **options) column, timestamps timestamps

Instance methods inherited from module Granite::Callbacks

abort!(message = "Aborted at #{@_current_callback}.") abort!

Macros inherited from module Granite::Callbacks

__after_create __after_create, __after_destroy __after_destroy, __after_save __after_save, __after_update __after_update, __before_create __before_create, __before_destroy __before_destroy, __before_save __before_save, __before_update __before_update, after_create(*callbacks, &block) after_create, after_destroy(*callbacks, &block) after_destroy, after_save(*callbacks, &block) after_save, after_update(*callbacks, &block) after_update, before_create(*callbacks, &block) before_create, before_destroy(*callbacks, &block) before_destroy, before_save(*callbacks, &block) before_save, before_update(*callbacks, &block) before_update

Macros inherited from module Granite::Associations

belongs_to(model, **options) belongs_to, has_many(model, **options) has_many, has_one(model, **options) has_one

Class Method Detail

def self.adapter #

[View source]
def self.connection_switch_wait_period : Int32 #

Default value for the time a model waits before using a reader database connection for read operations all models use this value. Change it to change it in all Granite::Base models.


def self.connection_switch_wait_period=(connection_switch_wait_period : Int32) #

Default value for the time a model waits before using a reader database connection for read operations all models use this value. Change it to change it in all Granite::Base models.


def self.current_adapter : Granite::Adapter::Base | Nil #

def self.current_adapter=(current_adapter : Granite::Adapter::Base | Nil) #

def self.last_write_time #

[View source]
def self.reader_adapter : Granite::Adapter::Base | Nil #

def self.reader_adapter=(reader_adapter : Granite::Adapter::Base | Nil) #

def self.schedule_adapter_switch #

[View source]
def self.switch_to_reader_adapter #

[View source]
def self.switch_to_writer_adapter #

[View source]
def self.time_since_last_write #

[View source]
def self.update_last_write_time #

This is done this way because callbacks don't work on class mthods


[View source]
def self.writer_adapter : Granite::Adapter::Base | Nil #

def self.writer_adapter=(writer_adapter : Granite::Adapter::Base | Nil) #

Instance Method Detail

def schedule_adapter_switch #

[View source]
def switch_to_reader_adapter #

[View source]
def switch_to_writer_adapter #

[View source]
def time_since_last_write #

[View source]
def update_last_write_time #

[View source]