Created
June 30, 2010 02:42
-
-
Save pjb3/458158 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://gist.github.com/458158 | |
require 'rubygems' | |
require 'dm-core' | |
require 'dm-migrations' | |
DataMapper::Logger.new($stdout, :debug) | |
DataMapper.setup(:default, 'sqlite::memory:') | |
class Thing | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
end | |
DataMapper.setup(:foo, 'sqlite3:///tmp/foo.db') | |
DataMapper.auto_migrate! :foo | |
repository(:foo) do | |
Thing.create :name => "I'm in foo!" | |
end | |
DataMapper.setup(:bar, 'sqlite3:///tmp/bar.db') | |
DataMapper.auto_migrate! :bar | |
repository(:bar) do | |
Thing.create :name => "I'm in bar!" | |
end | |
# Trying to re-create an already existing repo doesn't cause a problem | |
DataMapper.setup(:foo, 'sqlite3:///tmp/foo.db') | |
repository(:foo) do | |
Thing.create :name => "I'm in foo again!" | |
end | |
repository(:foo) do | |
puts "Things in foo: #{Thing.all.map{|t| t.name}.inspect}" | |
end | |
repository(:bar) do | |
puts "Things in bar: #{Thing.all.map{|t| t.name}.inspect}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment