Created
December 7, 2012 04:50
-
-
Save kimoto/4230842 to your computer and use it in GitHub Desktop.
O/R MapperであるDataMapperの遅延評価の仕組みのサンプル
This file contains hidden or 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
#!/bin/env ruby | |
# encoding: utf-8 | |
# Author: kimoto | |
require 'data_mapper' | |
class Channel | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
end | |
DataMapper.setup(:default, "mysql://127.0.0.1/sample") | |
DataMapper.finalize | |
DataMapper.auto_upgrade! | |
100.times{ |n| | |
Channel.create(:name => "ch#{n}") | |
} | |
DataMapper.logger.set_log STDERR, :debug, "", true # ログ出力を有効化 | |
channels = Channel.all | |
channels.each{ |ch| | |
ch.name # nop | |
} | |
# このとき実際に発行されるSQLは以下のみ | |
# (0.000365) SELECT `id`, `name` FROM `channels` ORDER BY `id` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment