DataMapper is a fast, thread-safe and feature rich Ruby ORM. The chassis-datamapper gem adds DataMapper gems, config, templates, and Rake tasks to Chassis.

Requirements

Installation

Add the chassis-datamapper extension to your gemfile:

gem 'chassis-datamapper'

Then run bundle install again.

Setup

Using DataMapper requires a bit of setup. Running rake datamapper:setup gets the process started:

  • The data_mapper gem is added to your Gemfile.
  • The dm-sqlite-adapter, dm-mysql-adapter, and dm-postgres-adapter adapters are added to your Gemfile.
  • Make sure to uncomment and group your development and production gems. Typically, the resulting Gemfile will include something like this:
gem 'data_mapper',         '~> 1.2.0'
gem 'dm-sqlite-adapter',   '~> 1.2.0', group: :development
gem 'dm-postgres-adapter', '~> 1.2.0', group: :production
  • DataMapper.setup is used in /settings/datamapper.rb to set database connection strings.
  • DataMapper.finalize is added to the end of app.rb to initialize all your models.

After adding DataMapper to the Gemfile, you'll need to run bundle install again.

Models and Auto Upgrading

This examples create a User model.

Models and tests can be added with the task rake dm:add:model[user].

Instead of running a migration, DataMapper can use the auto_upgrade! method to non-destructively bring your database up to date with your models by running rake dm:upgrade[User].

Leaving out the [model] argument will upgrade your database to match all your models: rake dm:upgrade.

Migrations

The task rake dm:migrate[User] is similar to dm:upgrade[model], only it's destructive.

Again, like dm:upgrade[model], leaving off the [model] argument will auto migrate your database to match all your models.

To add a custom migration, use the task rake dm:add:migration[add_users]. The name argument is required to name your migration.

The new migration includes timestamp, which is used for migrating up or down to a specific migration: rake dm:migrate:up[20130130013853] or rake dm:migrate:down[20130130013853].

Seed Data

This example adds a list of states as seed data.

If your database needs seed data to run, use the task rake dm:add:seed[add_list_of_states].

After filling out the seed script, run it with the rake task dm:seed[add_list_of_states].

Leaving out the [file] argument will run all the scripts in /data/seeds.

Release Notes

v1.0.1 (June 27, 2013)
  • Comments out the default SQLite setting.
v1.0.0 (June 16, 2013)
  • First!

License

Copyright (C) 2013 Jarrod Taylor.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.