Skip to content

Instantly share code, notes, and snippets.

@ess
Created August 1, 2009 14:10
Show Gist options
  • Save ess/159662 to your computer and use it in GitHub Desktop.
Save ess/159662 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'dm-tokyo-adapter'
# Tokyo Tyrant connection.
# start the server with the following:
#
# ttserver -port 1978 somefile.tct
DataMapper.setup(:default, :adapter => 'tokyo_tyrant', :host => 'localhost', :port => 1978 )
# Define your DataMapper resource and start saving:
class User
include DataMapper::Resource
property :user_id, Serial
property :name, String
property :age, Integer
has n, :posts
end
class Post
include DataMapper::Resource
property :post_id, Serial
property :content, String
belongs_to :user
end
u1 = User.create(:name => "Some Guy", :age => 239)
u2 = User.create(:name => "Bono", :age => 13)
u3 = User.create(:name => "Yet Another Guy", :age => 43)
p1 = Post.create(:content => "i left my heard in san francisco and my brain in los angelos")
p2 = Post.create(:content => "my heart just made me bitter and my brain just made me dangerous")
p3 = Post.create(:content => "the world is a wasteland from green bay to graceland")
p4 = Post.create(:content => "there's no-one fit to lead the human race")
p5 = Post.create(:content => "and you know that we are")
p6 = Post.create(:content => "the throwbacks, the retards")
p7 = Post.create(:content => "the ever growing face")
p8 = Post.create(:content => "of")
p9 = Post.create(:content => "human waste")
u1.posts << p1
p1.save
u1.posts << p2
p2.save
u2.posts << p3
p3.save
u3.posts << p4
p4.save
u3.posts << p5
p5.save
u1.posts << p6
p6.save
u2.posts << p7
p7.save
u3.posts << p8
p8.save
u1.posts << p9
p9.save
User.all(:user_id.gt => -1).each do |x|
puts x.name
x.posts.reload.each do |p|
puts "\t#{p.content}\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment