Skip to content

Instantly share code, notes, and snippets.

@warrickcustomhomes
Created June 30, 2010 18:35
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 warrickcustomhomes/c1c778db9586d43ae1ed to your computer and use it in GitHub Desktop.
Save warrickcustomhomes/c1c778db9586d43ae1ed to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'dm-types'
class Simulation
include DataMapper::Resource
property :id, UUID, :key => true, :index => true, :default => lambda { UUIDTools::UUID.random_create }
has n, :outages
end
class Outage
include DataMapper::Resource
property :id, Serial
belongs_to :simulation
end
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'postgres:///test')
DataMapper.auto_migrate!
sim = Simulation.create
sim.outages.create
sim.outages.create
sim.outages.create
sim.outages.create
sim.outages.create
sim.outages.create
puts sim.outages.count
simulation = Simulation.get(sim.id)
puts simulation.outages.count
scrapcoder@scraptop:~$ ruby test.rb
~ (0.000222) SET backslash_quote = off
~ (0.000097) SET standard_conforming_strings = on
~ (0.000084) SET client_min_messages = warning
~ (0.000522) SELECT version()
~ (0.000090) SET client_min_messages = warning
~ (0.003987) DROP TABLE IF EXISTS "simulations"
~ (0.000127) RESET client_min_messages
~ (0.000142) SET client_min_messages = warning
~ (0.000293) SELECT current_schema()
~ (0.004665) SELECT COUNT(*) FROM "information_schema"."tables" WHERE "table_type" = 'BASE TABLE' AND "table_schema" = 'public' AND "table_name" = 'simulations'
~ (0.005225) CREATE TABLE "simulations" ("id" VARCHAR(36) NOT NULL, PRIMARY KEY("id"))
~ (0.001874) CREATE INDEX "index_simulations_id" ON "simulations" ("id")
~ (0.000176) RESET client_min_messages
~ (0.000091) SET client_min_messages = warning
~ (0.003477) DROP TABLE IF EXISTS "outages"
~ (0.000120) RESET client_min_messages
~ (0.000143) SET client_min_messages = warning
~ (0.001163) SELECT COUNT(*) FROM "information_schema"."tables" WHERE "table_type" = 'BASE TABLE' AND "table_schema" = 'public' AND "table_name" = 'outages'
~ (0.005118) CREATE TABLE "outages" ("id" SERIAL NOT NULL, "simulation_id" VARCHAR(36) NOT NULL, PRIMARY KEY("id"))
~ (0.001907) CREATE INDEX "index_outages_simulation" ON "outages" ("simulation_id")
~ (0.000178) RESET client_min_messages
~ (0.001008) INSERT INTO "simulations" ("id") VALUES ('b1051a24-f06c-46ec-9fa6-7791a5113000')
~ (0.001214) INSERT INTO "outages" ("simulation_id") VALUES ('b1051a24-f06c-46ec-9fa6-7791a5113000') RETURNING "id"
~ (0.000731) INSERT INTO "outages" ("simulation_id") VALUES ('b1051a24-f06c-46ec-9fa6-7791a5113000') RETURNING "id"
~ (0.000531) INSERT INTO "outages" ("simulation_id") VALUES ('b1051a24-f06c-46ec-9fa6-7791a5113000') RETURNING "id"
~ (0.000485) INSERT INTO "outages" ("simulation_id") VALUES ('b1051a24-f06c-46ec-9fa6-7791a5113000') RETURNING "id"
~ (0.000501) INSERT INTO "outages" ("simulation_id") VALUES ('b1051a24-f06c-46ec-9fa6-7791a5113000') RETURNING "id"
~ (0.000501) INSERT INTO "outages" ("simulation_id") VALUES ('b1051a24-f06c-46ec-9fa6-7791a5113000') RETURNING "id"
6
~ (0.000769) SELECT "id" FROM "simulations" WHERE "id" = 'b1051a24-f06c-46ec-9fa6-7791a5113000' ORDER BY "id" LIMIT 1
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment