Skip to content

Instantly share code, notes, and snippets.

@jeffreybasurto
Created October 13, 2011 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreybasurto/1285812 to your computer and use it in GitHub Desktop.
Save jeffreybasurto/1285812 to your computer and use it in GitHub Desktop.
require 'data_mapper'
# so we can see how long the database hits take.
DataMapper::Logger.new($stdout, :debug)
#DataMapper.setup(:default, "sqlite://#{File.expand_path(File.dirname(File.expand_path(__FILE__)) + '/data.db')}")
DataMapper.setup(:default, 'sqlite::memory:')
class Entry
include DataMapper::Resource
property :id, Serial
property :field, Integer
end
DataMapper.finalize # finalizes changes to model structure for database.
DataMapper.auto_migrate! # structures database to fit the model
# create 5000 entries
5000.times { Entry.create }
# just access the field of a single entry
Entry.first.field
# does nothing but access each field
Entry.all.each &:field
# update a single field to a new value.
Entry.first.update({:field=>99999})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment