Skip to content

Instantly share code, notes, and snippets.

@kematzy
Created October 1, 2010 01:20
Show Gist options
  • Select an option

  • Save kematzy/605576 to your computer and use it in GitHub Desktop.

Select an option

Save kematzy/605576 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-sqlite-adapter'
require 'data_mapper'
class Test
include DataMapper::Resource
property :id, Serial
property :title, String, :length => 255
property :description, String, :length => 255
end
DataMapper.setup( :default, "sqlite3::memory:" )
DataMapper.auto_migrate!
create_new_record = Test.first_or_create(
'title' => 'A',
'description' => 'B'
)
if create_new_record.save
puts "New Record was saved: [#{create_new_record.inspect}]"
else
puts "New Record was NOT saved: [#{create_new_record.inspect}]"
end
use_first_record = Test.first_or_create(
'title' => 'A',
'description' => 'B'
)
if use_first_record.save
puts "First Record was 'saved': [#{use_first_record.inspect}]"
else
puts "First Record was NOT saved: [#{use_first_record.inspect}]"
end
puts "\nTest.all =[#{Test.all.inspect}]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment