Module DataMapper
In: lib/dm-core/query/path.rb
lib/dm-core/query/sort.rb
lib/dm-core/query/operator.rb
lib/dm-core/query/conditions/operation.rb
lib/dm-core/query/conditions/comparison.rb
lib/dm-core/query/direction.rb
lib/dm-core/repository.rb
lib/dm-core/support/inflector/methods.rb
lib/dm-core/support/inflector/inflections.rb
lib/dm-core/support/naming_conventions.rb
lib/dm-core/support/local_object_space.rb
lib/dm-core/support/deprecate.rb
lib/dm-core/support/chainable.rb
lib/dm-core/support/ordered_set.rb
lib/dm-core/support/equalizer.rb
lib/dm-core/support/subject.rb
lib/dm-core/support/ext/array.rb
lib/dm-core/support/ext/module.rb
lib/dm-core/support/ext/string.rb
lib/dm-core/support/ext/hash.rb
lib/dm-core/support/ext/object.rb
lib/dm-core/support/ext/try_dup.rb
lib/dm-core/support/ext/blank.rb
lib/dm-core/support/mash.rb
lib/dm-core/support/descendant_set.rb
lib/dm-core/support/logger.rb
lib/dm-core/support/hook.rb
lib/dm-core/support/inflections.rb
lib/dm-core/support/subject_set.rb
lib/dm-core/support/assertions.rb
lib/dm-core/version.rb
lib/dm-core/property.rb
lib/dm-core/adapters/in_memory_adapter.rb
lib/dm-core/adapters/abstract_adapter.rb
lib/dm-core/collection.rb
lib/dm-core/resource.rb
lib/dm-core/associations/one_to_one.rb
lib/dm-core/associations/relationship.rb
lib/dm-core/associations/one_to_many.rb
lib/dm-core/associations/many_to_one.rb
lib/dm-core/associations/many_to_many.rb
lib/dm-core/backwards.rb
lib/dm-core/spec/setup.rb
lib/dm-core/spec/lib/adapter_helpers.rb
lib/dm-core/spec/lib/pending_helpers.rb
lib/dm-core/spec/lib/spec_helper.rb
lib/dm-core/spec/lib/collection_helpers.rb
lib/dm-core/query.rb
lib/dm-core/identity_map.rb
lib/dm-core/adapters.rb
lib/dm-core/property/boolean.rb
lib/dm-core/property/typecast/time.rb
lib/dm-core/property/typecast/numeric.rb
lib/dm-core/property/class.rb
lib/dm-core/property/date.rb
lib/dm-core/property/date_time.rb
lib/dm-core/property/text.rb
lib/dm-core/property/time.rb
lib/dm-core/property/float.rb
lib/dm-core/property/decimal.rb
lib/dm-core/property/discriminator.rb
lib/dm-core/property/lookup.rb
lib/dm-core/property/binary.rb
lib/dm-core/property/string.rb
lib/dm-core/property/object.rb
lib/dm-core/property/integer.rb
lib/dm-core/property/serial.rb
lib/dm-core/property/numeric.rb
lib/dm-core/relationship_set.rb
lib/dm-core/property_set.rb
lib/dm-core/model.rb
lib/dm-core/model/property.rb
lib/dm-core/model/is.rb
lib/dm-core/model/scope.rb
lib/dm-core/model/relationship.rb
lib/dm-core/model/hook.rb
lib/dm-core/resource/persistence_state.rb
lib/dm-core/resource/persistence_state/dirty.rb
lib/dm-core/resource/persistence_state/clean.rb
lib/dm-core/resource/persistence_state/transient.rb
lib/dm-core/resource/persistence_state/persisted.rb
lib/dm-core/resource/persistence_state/immutable.rb
lib/dm-core/resource/persistence_state/deleted.rb
lib/dm-core.rb

Setup and Configuration

DataMapper uses URIs or a connection hash to connect to your data-store. URI connections takes the form of:

  DataMapper.setup(:default, 'protocol://username:password@localhost:port/path/to/repo')

Breaking this down, the first argument is the name you wish to give this connection. If you do not specify one, it will be assigned :default. If you would like to connect to more than one data-store, simply issue this command again, but with a different name specified.

In order to issue ORM commands without specifying the repository context, you must define the :default database. Otherwise, you‘ll need to wrap your ORM calls in repository(:name) { }.

Second, the URI breaks down into the access protocol, the username, the server, the password, and whatever path information is needed to properly address the data-store on the server.

Here‘s some examples

  DataMapper.setup(:default, 'sqlite3://path/to/your/project/db/development.db')
  DataMapper.setup(:default, 'mysql://localhost/dm_core_test')
    # no auth-info
  DataMapper.setup(:default, 'postgres://root:supahsekret@127.0.0.1/dm_core_test')
    # with auth-info

Alternatively, you can supply a hash as the second parameter, which would take the form:

  DataMapper.setup(:default, {
    :adapter  => 'adapter_name_here',
    :database => 'path/to/repo',
    :username => 'username',
    :password => 'password',
    :host     => 'hostname'
  })

Logging

To turn on error logging to STDOUT, issue:

  DataMapper::Logger.new($stdout, :debug)

You can pass a file location ("/path/to/log/file.log") in place of $stdout. see DataMapper::Logger for more information.

Methods

finalize   repository   root   setup  

Classes and Modules

Module DataMapper::Adapters
Module DataMapper::Assertions
Module DataMapper::Associations
Module DataMapper::Chainable
Module DataMapper::Deprecate
Module DataMapper::Equalizer
Module DataMapper::Ext
Module DataMapper::Hook
Module DataMapper::Inflector
Module DataMapper::LocalObjectSpace
Module DataMapper::Model
Module DataMapper::NamingConventions
Module DataMapper::Resource
Module DataMapper::Spec
Module DataMapper::Subject
Module DataMapper::Undefined
Class DataMapper::Collection
Class DataMapper::DescendantSet
Class DataMapper::IdentityMap
Class DataMapper::ImmutableDeletedError
Class DataMapper::ImmutableError
Class DataMapper::IncompleteModelError
Class DataMapper::Logger
Class DataMapper::Mash
Class DataMapper::ObjectNotFoundError
Class DataMapper::OrderedSet
Class DataMapper::PersistenceError
Class DataMapper::PluginNotFoundError
Class DataMapper::Property
Class DataMapper::PropertySet
Class DataMapper::Query
Class DataMapper::RelationshipSet
Class DataMapper::Repository
Class DataMapper::RepositoryNotSetupError
Class DataMapper::SaveFailureError
Class DataMapper::SubjectSet
Class DataMapper::UnknownRelationshipError
Class DataMapper::UnsavedParentError
Class DataMapper::UpdateConflictError

Constants

VERSION = '1.2.0.rc1'

Attributes

logger  [RW] 

Public Class methods

Perform necessary steps to finalize DataMapper for the current repository

This method should be called after loading all models and plugins.

It ensures foreign key properties and anonymous join models are created. These are otherwise lazily declared, which can lead to unexpected errors. It also performs basic validity checking of the DataMapper models.

@return [DataMapper] The DataMapper module

@api public

Block Syntax

  Pushes the named repository onto the context-stack,
  yields a new session, and pops the context-stack.

Non-Block Syntax

  Returns the current session, or if there is none,
  a new Session.

@param [Symbol] args the name of a repository to act within or return, :default is default

@yield [Proc] (optional) block to execute within the context of the named repository

@api public

@api private

Setups up a connection to a data-store

@param [Symbol] name

  a name for the context, defaults to :default

@param [Hash(Symbol => String), Addressable::URI, String] uri_or_options

  connection information

@return [DataMapper::Adapters::AbstractAdapter]

  the resulting setup adapter

@raise [ArgumentError] "name must be a Symbol, but was…"

  indicates that an invalid argument was passed for name[Symbol]

@raise [ArgumentError] "uri_or_options must be a Hash, URI or String, but was…"

  indicates that connection information could not be gleaned from
  the given uri_or_options[Hash, Addressable::URI, String]

@api public

[Validate]