abstract class PgORM::Base

Included Modules

Extended Modules

Defined in:

pg-orm/base.cr

Constant Summary

AM_PARENT_TYPE = {:type => PgORM::Base} of Nil => Nil
TABLES = [] of String

Constructors

Class Method Summary

Macro Summary

Instance Method Summary

Macros inherited from module PgORM::Validators

ensure_unique(field, scope = [] of Nil, callback = nil, &transform) ensure_unique

Macros inherited from module PgORM::Table

__process_table__ __process_table__, table(name) table

Instance methods inherited from module PgORM::Persistence

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

Macros inherited from module PgORM::Associations

__process_assoc_serialization__ __process_assoc_serialization__, belongs_to(name, class_name = nil, foreign_key = nil, autosave = nil, dependent = nil) belongs_to, has_many(name, class_name = nil, foreign_key = nil, autosave = nil, dependent = nil, serialize = false) has_many, has_one(name, class_name = nil, foreign_key = nil, autosave = nil, dependent = nil) has_one

Constructor Detail

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

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

[View source]
def self.new(rs : DB::ResultSet) #

[View source]

Class Method Detail

def self.attributes : Array(Symbol) #

Returns all attribute keys.


def self.clear #

Removes all records from the table


[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.delete(*ids) : Nil #

Deletes one or many records identified by ids from the database.

User.delete(1)
User.delete(1, 2, 3)

[View source]
def self.from_rs(rs : DB::ResultSet) #

[View source]
def self.truncate(cascade = true) #

Truncate quickly removes all from table.


[View source]
def self.update(id, args) : Nil #

Updates one or many records identified by id in the database.

User.update(1, {name: user})
User.update([1, 2, 3], {group_id: 2})

[View source]
def self.update(id, **args) : Nil #

Updates one or many records identified by id in the database.

User.update(1, {name: user})
User.update([1, 2, 3], {group_id: 2})

[View source]

Macro Detail

macro __customize_orm__ #

[View source]
macro __nilability_validation__ #

[View source]
macro default_primary_key(name, autogenerated = true, converter = nil, **tags) #

[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(params : HTTP::Params | Hash(String, String) | Tuple(String, String)) #

Assign to mulitple attributes via HTTP::Params.


def assign_attributes(model : PgORM::Base) #

Assign to multiple attributes from a model object


def assign_attributes #

Assign to multiple attributes.


def attributes #

Returns a Hash of all attribute values


def attributes_tuple #

Returns a NamedTuple of all attribute values.


def extra_attributes : Hash(String, PgORM::Value) #

[View source]
abstract def id #

Always returns this record's primary key value, even when the primary key isn't named #id


[View source]
abstract def id? #

Same as #id but may return nil when the record hasn't been saved instead of raising.


[View source]
def persistent_attributes #

Returns a Hash of all attributes that can be persisted.


def primary_key #

[View source]
def to_json(json : JSON::Builder) #

[View source]