Getting started with DataMapper

Getting started with DataMapper

 

 

官网:http://datamapper.org/getting-started.html

 

gem install dm-core

 

gem install dm-mysql-adapter

 

gem install data_mapper

 

require 'rubygems'
require 'data_mapper'

# Open the database test1.db
#'mysql://user:password@hostname/database'
DataMapper.setup :default, "mysql://root:123456@localhost/cc"

# Define the Person model
class Person
  include DataMapper::Resource

  property :firstname, String
  property :lastname, String
  property :email, String, :key => true
end

# Automatically create the tables if they don't exist
DataMapper.auto_migrate!

# Create a new record
p = Person.new
p.attributes = {
  :firstname => 'John',
  :lastname => 'Doe',
  :email => '[email protected]'
}

# Save it to the database
p.save

 
Getting started with DataMapper
 

参考资料 :http://ruby.about.com/od/sinatra/a/datamapper.htm

你可能感兴趣的:(datamapper,dm-core)