dm-mapping (1)
from Lin Jen-Shin
to DataMapper
cc godfat 真常
date Mon, Jul 28, 2008 at 12:30 AM
subject Re: Manipulate an existing database.
mailed-by gmail.com
On Jul 27, 6:33 pm, "Michael Klishin" wrote:
I was not familiar with SQL, and I found that it was database dependent.
Anyway, I have just created a project *dm-mapping* for testing the thought.
http://github.com/godfat/dm-mapping
Though currently only sqlite3 is supported,
feel free to fork it or use it somewhere.
(sql codes were borrowed from activerecord 2.1)
Here's the updated thought of usage:
== SYNOPSIS:
require 'dm-core'
# setup first, or dm-mapping can't determine which adapter it should load up
DataMapper.setup :default, 'sqlite3://db/development.sqlite3'
require 'dm-mapping'
class User
include DataMapper::Resource
mapping /.*/
mapping DataMapper::Mapping::All
mapping /_at$/, /^salt_/
mapping :account, :email
mapping *storage_fields
end
DataMapper.repository.storages
# => ['users']
User.storage_fields
# => ['account', 'email', 'created_at', 'salt_first', 'salt_second']
DataMapper.repository.fields('users')
# => ['account', 'email', 'created_at', 'salt_first', 'salt_second']
DataMapper.repository.storages_and_fields
# => {'users' => ['account', 'email', 'created_at', 'salt_first', 'salt_second']}
Thanks for your listening,
0 retries:
Post a Comment
Note: Only a member of this blog may post a comment.