Skip to content
royw edited this page Aug 15, 2012 · 1 revision

Datamapper is pretty easy to use from Ramaze. Note this example is a little dated, you will want to use the latest version of datamapper.

Configuration

Gemfile

Add datamapper dependencies to your Gemfile

gem 'data_mapper', "~> 1.1.0"
gem 'dm-sqlite-adapter', "~> 1.1.0"
gem 'extlib', "~> 0.9.15"
gem 'dm-zone-types', "~> 0.3"
gem 'i18n', "~> 0.6.0"

# We can technically use the 1.1 gem, but it throws up deprecation warnings.
# This ref is the commit the warnings were silenced, but is before the DM
# dependencies were bumped to 1.1.1 (which hasn't been released yet)
gem 'dm-do-adapter',
  git: 'git://github.com/datamapper/dm-do-adapter',
  ref: '7f0b53d1ada8735910e0'

app.rb

Here's an example app.rb that includes datamapper:

# This file contains your application, it requires dependencies and necessary parts of
# the application.
#
# It will be required from either `config.ru` or `start.rb`
require 'rubygems'
require 'ramaze'

# Make sure that Ramaze knows where you are
Ramaze.options.roots = [__DIR__]

require 'data_mapper'
require 'dm-zone-types'
require 'extlib'
require 'pp'

# If you want the logs displayed you have to do this before the call to setup

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

# An in-memory Sqlite3 connection:
# DataMapper.setup(:default, 'sqlite::memory:')
DataMapper.setup(:default, 'sqlite::memory:')

# A Sqlite3 connection to a persistent database
# DataMapper.setup(:default, 'sqlite:///path/to/project.db')

# A MySQL connection:
# DataMapper.setup(:default, 'mysql://localhost/the_database_name')

# A Postgres connection:
# DataMapper.setup(:default, 'postgres://localhost/the_database_name')

# Initialize controllers and models
require __DIR__('model/init')
require __DIR__('controller/init')

# require 'dm-migrations'
DataMapper.auto_migrate!
Clone this wiki locally