Class BigRecord::Base
In: lib/big_record/base.rb
lib/big_record/connection_adapters/hbase_adapter.rb
lib/big_record/connection_adapters/abstract/connection_specification.rb
lib/big_record/connection_adapters/hbase_rest_adapter.rb
lib/big_record/connection_adapters/cassandra_adapter.rb
Parent: Model

Methods

Constants

VALID_FIND_OPTIONS = [:limit, :offset, :include, :view, :versions, :timestamp, :include_deleted, :force_reload, :columns, :stop_row]

Attributes

modified_attributes  [RW] 

Public Class methods

@return [Class] The base class which inherits BigRecord::Base directly.

Clears the cache which maps classes to connections.

Clears the cache which maps classes

Return the list of fully qualified column names, i.e. ["family:qualifier"].

Returns the column names based on the options argument in order of :columns,then :view, i.e. disregards :view if :columns is defined.

@option options [Array<String, Symbol>] :columns List of fully qualified column names or column aliases. @option options [String, Symbol] :view The name of the view as defined with {view}.

Returns true if a connection that‘s accessible to this class have already been opened.

Returns the connection currently associated with the class. This can also be used to "borrow" the connection to do database work unrelated to any of the specific Active Records.

Creates an object, instantly saves it as a record (if the validation permits it), and returns it. If the save fails under validations, the unsaved object is still returned.

Default columns to create with the model, such as primary key.

Get the default column family used to store attributes that have no column family set explicitly.

Defaults to "attribute"

Return the hash of default views which consist of all columns and the :default named views.

Deletes the record with the given id without instantiating an object first. If an array of ids is provided, all of them are deleted.

Deletes all the records that match the condition without instantiating the objects first (and hence not calling the destroy method). Example:

  Post.delete_all "person_id = 5 AND (category = 'Something' OR category = 'Else')"

@todo take into consideration the conditions

Destroys the record with the given id by instantiating the object and calling destroy (all the callbacks are the triggered). If an array of ids is provided, all of them are destroyed.

Destroys the objects for all the records that match the condition by instantiating each object and calling the destroy method. Example:

  Person.destroy_all "last_login < '2004-04-04'"

Establishes the connection to the database. Accepts a hash as input where the :adapter key must be specified with the name of a database adapter (in lower-case) example for regular databases (MySQL, Postgresql, etc):

  ActiveRecord::Base.establish_connection(
    :adapter  => "mysql",
    :host     => "localhost",
    :username => "myuser",
    :password => "mypass",
    :database => "somedatabase"
  )

Example for SQLite database:

  ActiveRecord::Base.establish_connection(
    :adapter => "sqlite",
    :database  => "path/to/dbfile"
  )

Also accepts keys as strings (for parsing from yaml for example):

  ActiveRecord::Base.establish_connection(
    "adapter" => "sqlite",
    "database"  => "path/to/dbfile"
  )

The exceptions AdapterNotSpecified, AdapterNotFound and ArgumentError may be returned on an error.

Returns true if the given id represents the primary key of a record in the database, false otherwise.

Return the list of families for this class

Establishes a connection to the database that‘s used by all Active Record objects.

New objects can be instantiated as either empty (pass no construction parameter) or pre-set with attributes but not yet saved (pass a hash with key names matching the associated table column names). In both instances, valid attribute keys are determined by the column names of the associated table — hence you can‘t have attributes that aren‘t part of the table columns.

Return the name of the primary key. Defaults to "id".

Remove the connection for this class. This will close the active connection and the defined connection (if they exist). The result can be used as argument for establish_connection, for easy re-establishing of the connection.

HBase scanner utility — scans the table and executes code on each record

@example

   Entity.scan(:batch_size => 200) {|e|puts "#{e.name} is a child!" if e.parent}

@option options [Integer] :batch_size - number of records to retrieve from database with each scan iteration. @option options [Block] :code - the code to execute (see example above for syntax)

Set the default column family used to store attributes that have no column family set explicitly.

@example

  set_default_family :attr  # instead of using :attribute as the default.

Truncate the table for this model

Finds the record from the passed id, instantly saves it with the passed attributes (if the validation permits it), and returns it. If the save fails under validations, the unsaved object is still returned.

The arguments may also be given as arrays in which case the update method is called for each pair of id and attributes and an array of objects is returned.

@example of updating one record:

  Person.update(15, {:user_name => 'Samuel', :group => 'expert'})

@example of updating multiple records:

  people = { 1 => { "first_name" => "David" }, 2 => { "first_name" => "Jeremy"} }
  Person.update(people.keys, people.values)

Updates all records with the SET-part of an SQL update statement in updates and returns an integer with the number of rows updated. A subset of the records can be selected by specifying conditions. Example:

  Billing.update_all "category = 'authorized', approved = 1", "author = 'David'"

Macro for defining a named view to a list of columns.

@param [String, Symbol] name Give it an arbitrary name. @param [Array<String, Symbol>] columns List of columns to associate to this view. Can use column aliases or fully qualified names.

@example

  view :front_page, :name, :title, :description
  view :summary, ["attribute:name", "attribute:title"]

Get a list of view names defined by {view}.

Get a list of all the views defined by the {view} macro for the model.

Get the full hash of views consisting of the name as keys, and the {ConnectionAdapters::View} views.

Protected Class methods

Add the missing cells to the raw record and set them to nil. We know that it‘s nil because else we would have received those cells. That way, when the value of one of these cells will be requested by the client we won‘t try to lazy load it.

Define aliases to the fully qualified attributes

Public Instance methods

Returns the value of the attribute identified by attr_name after it has been typecast (for example, "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)). (Alias for the protected read_attribute method).

Returns the connection currently associated with the class. This can also be used to "borrow" the connection to do database work that isn‘t easily done without going straight to SQL.

Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can‘t be persisted).

Returns true if this object hasn‘t been saved yet — that is, a record for the object doesn‘t exist yet.

Returns the value of the attribute identified by attr_name after it has been typecast (for example, "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)).

Read an attribute that defines a column family.

  • No record exists: Creates a new record with values matching those of the object attributes.
  • A record does exist: Updates the record with values matching those of the object attributes.

Attempts to save the record, but instead of just returning false if it couldn‘t happen, it raises a RecordNotSaved exception

Updates a single attribute and saves the record. This is especially useful for boolean flags on existing records. Note: This method is overwritten by the Validation module that‘ll make sure that updates made with this method doesn‘t get subjected to validation checks. Hence, attributes can be updated even if the full object isn‘t valid.

Updates all the attributes from the passed-in Hash and saves the record. If the object is invalid, the saving will fail and false will be returned.

Updates an object just like Base.update_attributes but calls save! instead of save so an exception is raised if the record is invalid.

Protected Instance methods

Creates a record with values matching those of the instance attributes and returns its id. Generate a UUID as the row key.

Invoke {create} if {new_record} returns true, otherwise it‘s an {update}

Updates the associated record with values matching those of the instance attributes. Returns the number of affected rows.

Update this record in hbase. Cannot be directly in the method ‘update’ because it would trigger callbacks and therefore weird behaviors.

[Validate]