Created
May 13, 2010 11:52
-
-
Save akm/399748 to your computer and use it in GitHub Desktop.
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
# simply_stored | |
# gem install simply_stored right_aws uuidtools | |
require 'active_support' | |
require 'simply_stored/simpledb' | |
SimplyStored::Simple.aws_access_key = 'test1' | |
SimplyStored::Simple.aws_secret_access_key = 'test1' | |
conn = RightAws::ActiveSdb.establish_connection( | |
SimplyStored::Simple.aws_access_key, | |
SimplyStored::Simple.aws_secret_access_key, | |
:mode => :per_thread, | |
:server => '192.168.50.137', | |
:protocol => "http", | |
:port => 80, | |
:signature_version => 2, | |
:service => "/mdb/request.mgwsi" | |
) | |
conn.create_domain("users") | |
conn.create_domain("posts") | |
class User < SimplyStored::Simple | |
simpledb_string :login | |
simpledb_integer :age | |
# property :accepted_terms_of_service, :type => :boolean | |
simpledb_string :accepted_terms_of_service | |
simpledb_timestamp :last_login | |
require_attributes :login | |
has_many :posts | |
end | |
class Post < SimplyStored::Simple | |
simpledb_string :title | |
simpledb_string :body | |
simpledb_string :user_id | |
belongs_to :user | |
end | |
user = User.new(:age => 12, :accepted_terms_of_service => 'T', :last_login => Time.now) | |
user.save! # undefined method | |
user.save #=> false | |
user.errors #=> [["login", "is missing"]] | |
user = User.create(:login => 'Ben', :age => 122, :accepted_terms_of_service => 'T', :last_login => Time.now) | |
User.find_by_age(122) | |
post = Post.new(:title => 'My first post', :body => 'SimplyStored is so nice!') | |
post.user = user | |
post.save | |
user.posts | |
# 関連するモデルをcreateの引数で指定するとエラーになっちゃう | |
# Post.create(:title => 'My second post', :body => 'SimplyStored is so nice?', :user => user) | |
post = Post.new(:title => 'My second post', :body => 'SimplyStored is so nice?') | |
post.user = user | |
post.save | |
user.posts | |
user.posts(:force_reload => true) # このオプションは効かない | |
Post.find_all_by_title_and_user_id('My first post', user.id).first.body | |
post.delete # destroyは使えない |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment