Guest User

Untitled

a guest
May 25th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. # simply_stored
  2. # gem install simply_stored right_aws uuidtools
  3.  
  4. require 'active_support'
  5. require 'simply_stored/simpledb'
  6. SimplyStored::Simple.aws_access_key = 'test1'
  7. SimplyStored::Simple.aws_secret_access_key = 'test1'
  8.  
  9. conn = RightAws::ActiveSdb.establish_connection(
  10. SimplyStored::Simple.aws_access_key,
  11. SimplyStored::Simple.aws_secret_access_key,
  12. :mode => :per_thread,
  13. :server => '192.168.50.137',
  14. :protocol => "http",
  15. :port => 80,
  16. :signature_version => 2,
  17. :service => "/mdb/request.mgwsi"
  18. )
  19.  
  20. conn.create_domain("users")
  21. conn.create_domain("posts")
  22.  
  23. class User < SimplyStored::Simple
  24. simpledb_string :login
  25. simpledb_integer :age
  26. # property :accepted_terms_of_service, :type => :boolean
  27. simpledb_string :accepted_terms_of_service
  28. simpledb_timestamp :last_login
  29.  
  30. require_attributes :login
  31.  
  32. has_many :posts
  33. end
  34.  
  35. class Post < SimplyStored::Simple
  36. simpledb_string :title
  37. simpledb_string :body
  38.  
  39. simpledb_string :user_id
  40. belongs_to :user
  41. end
  42.  
  43. user = User.new(:age => 12, :accepted_terms_of_service => 'T', :last_login => Time.now)
  44. user.save! # undefined method
  45. user.save #=> false
  46. user.errors #=> [["login", "is missing"]]
  47.  
  48. user = User.create(:login => 'Ben', :age => 122, :accepted_terms_of_service => 'T', :last_login => Time.now)
  49.  
  50. User.find_by_age(122)
  51.  
  52.  
  53. post = Post.new(:title => 'My first post', :body => 'SimplyStored is so nice!')
  54. post.user = user
  55. post.save
  56. user.posts
  57.  
  58.  
  59. # 関連するモデルをcreateの引数で指定するとエラーになっちゃう
  60. # Post.create(:title => 'My second post', :body => 'SimplyStored is so nice?', :user => user)
  61. post = Post.new(:title => 'My second post', :body => 'SimplyStored is so nice?')
  62. post.user = user
  63. post.save
  64.  
  65. user.posts
  66. user.posts(:force_reload => true) # このオプションは効かない
  67.  
  68. Post.find_all_by_title_and_user_id('My first post', user.id).first.body
  69. post.delete # destroyは使えない
Add Comment
Please, Sign In to add comment