NoSQL   Ruby
         n
NoSQL         Ruby
               1


        n=1
(@Sixeight)
• NoSQL
• MongoDB
• MongoMapper
•
• NoSQL
• MongoDB
• MongoMapper
•
NoSQL
SQL
×
SQL
Not only SQL
CREATE TABLE cats (
   id int NOT NULL,
   name text,
   PRIMARY KEY (id)
);
INSERT INTO cats VALUES (1, “tama”);
CREATE TABLE cats (
   id int NOT NULL,
   name text,
   PRIMARY KEY (id)
);
INSERT INTO cats VALUES (1, “tama”);
$ mongo
> db.cats.insert({name: “tama”})
$ mongo
> db.cats.insert({name: “tama”})
> db.cats.insert({
     name: “goro”,
     dapple_color: “gray”
  })
> db.cats.fin...
• Google BigTable
• amazon Dynamo
• HBase
• Apache Casandra
• CounchDB
• MongoDB
• and more
• Google BigTable
• amazon Dynamo
• HBase
• Apache Casandra
• CounchDB
• MongoDB
• and more
• Google BigTable
• amazon Dynamo
• HBase
• Apache Casandra
• CounchDB
• MongoDB
• and more
• NoSQL
• MongoDB
• MongoMapper
•
MongoDB
  by 10gen
MongoDB   C++
                (wikipedia)
MongoDB   C++
                (wikipedia)
•                     (the simplicity and power of JSON-like data schemas)

•
•                                           ...
≒
≒
{ "_id" : ###, "name" : "tama" }
{ "_id" : ###, "name" : "tama" }
{ "_id" : ###, "name" : "goro", "dapple_color" : "gray" }
{ "_id" : ###, "name" : "tama" }
{ "_id" : ###, "name" : "goro", "dapple_color" : "gray" }
over 200 projects
• NoSQL
• MongoDB
• MongoMapper
•
MongoMapper
http://github.com/jnunemaker/mongomapper
ActiveRecord   API
          +
gem install mongo_mapper
class Cats
  include MongoMapper::Document

  key :name, String
end
irb
class Cats
  include MongoMapper::Document

  key :name, String
end
class Cats
  include MongoMapper::Document

  key :name, String
end
class Cats
  include MongoMapper::Document

  key :name, String
end
irb:001:0> Cats.create :name => 'tama'
irb:002:0> Cats.first
=> #<Cats name: "tama", _id: BSON::ObjectID('###')>
irb:003:0>...
Array, Binary, Boolean, Date, Float, Hash
 Integer, Nil, ObjectId, Set, String, Time
      Custom Type, and TypeLess
Array, Binary, Boolean, Date, Float, Hash
            TypeLess
 Integer, Nil, ObjectId, Set, String, Time
      Custom Typ...
class Storage
  include MongoMapper::Document

  key :value
end
class Storage
  include MongoMapper::Document

  key :value
end
irb:001:0> Storage.create :values => 25
irb:002:0> Storage.create :value => 'String'
irb:003:0> Cats.all
=> [#<Storage val...
Array, Binary, Boolean, Date, Float, Hash
 Integer, Nil, ObjectId, Set, String, Time
      Custom Type, and TypeLess
class Family
  include MongoMapper::Document
  key :name, String
  many :cats
end

class Cats
  include MongoMapper::Docum...
class Person
  include MongoMapper::Document
  key :name, String
  one :address
end

class Address
  include MongoMapper::...
• validates_presence_of :title
• validates_presence_of
• validates_length_of
• validates_format_of
• validated_numericalit...
class Cats
  include MongoMapper::Document
  key :name, String

  validates_presence_of :name
end
class Cats
  include MongoMapper::Document
  key :name, String, :required => true
end
class Cats
  include MongoMapper::Document
  key :name, String, :required => true
end
before / after
validate, create, save
class Cats
  include MongoMapper::Document
  key :name, String

  before_validation :add_nyan

  private
  def add_nyan
  ...
irb:001:0> Cats.create :name => 'tama'
irb:002:0> Cats.first
=> #<Cats name: "tama nyan", _id: BSON::ObjectID('###')>
module Charisma
  def fly
    puts “I’m flying”
  end
end

MongoMapper::Document.
  append_inclusions(Charisma)

Cats.firs...
module Charisma
  def fly
    puts “I’m flying”
  end
end

MongoMapper::Document.
  append_inclusions(Charisma)

Cats.firs...
• NoSQL
• MongoDB
• MongoMapper
•
MongoDB
DB
KVS   RDBMS
MongoMapper
ActiveRecord
         MongoDB
URL

•   http://www.mongodb.org/

•   http://www.mongodb.org/display/DOCSJP/Home

•   http://wiki.github.com/jnunemaker/mo...
by http://www.wanpug.com/
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
Upcoming SlideShare
Loading in …5
×

NoSQL を Ruby で実践するための n 個の方法

6,569 views
6,419 views

Published on

Published in: Technology
1 Comment
9 Likes
Statistics
Notes
No Downloads
Views
Total views
6,569
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
40
Comments
1
Likes
9
Embeds 0
No embeds

No notes for slide

NoSQL を Ruby で実践するための n 個の方法

  1. 1. NoSQL Ruby n
  2. 2. NoSQL Ruby 1 n=1
  3. 3. (@Sixeight)
  4. 4. • NoSQL • MongoDB • MongoMapper •
  5. 5. • NoSQL • MongoDB • MongoMapper •
  6. 6. NoSQL
  7. 7. SQL
  8. 8. × SQL
  9. 9. Not only SQL
  10. 10. CREATE TABLE cats ( id int NOT NULL, name text, PRIMARY KEY (id) ); INSERT INTO cats VALUES (1, “tama”);
  11. 11. CREATE TABLE cats ( id int NOT NULL, name text, PRIMARY KEY (id) ); INSERT INTO cats VALUES (1, “tama”);
  12. 12. $ mongo > db.cats.insert({name: “tama”})
  13. 13. $ mongo > db.cats.insert({name: “tama”}) > db.cats.insert({ name: “goro”, dapple_color: “gray” }) > db.cats.find() { "_id" : ObjectId("4c49118783d1600c126d2147"), "name" : "tama" } { "_id" : ObjectId("4c49119983d1600c126d2148"), "name" : "goro", "dapple_color" : "gray" }
  14. 14. • Google BigTable • amazon Dynamo • HBase • Apache Casandra • CounchDB • MongoDB • and more
  15. 15. • Google BigTable • amazon Dynamo • HBase • Apache Casandra • CounchDB • MongoDB • and more
  16. 16. • Google BigTable • amazon Dynamo • HBase • Apache Casandra • CounchDB • MongoDB • and more
  17. 17. • NoSQL • MongoDB • MongoMapper •
  18. 18. MongoDB by 10gen
  19. 19. MongoDB C++ (wikipedia)
  20. 20. MongoDB C++ (wikipedia)
  21. 21. • (the simplicity and power of JSON-like data schemas) • • Index • • in-place • large objects ( ) • • sharding • MapReduce •
  22. 22. ≒ ≒
  23. 23. { "_id" : ###, "name" : "tama" }
  24. 24. { "_id" : ###, "name" : "tama" } { "_id" : ###, "name" : "goro", "dapple_color" : "gray" }
  25. 25. { "_id" : ###, "name" : "tama" } { "_id" : ###, "name" : "goro", "dapple_color" : "gray" }
  26. 26. over 200 projects
  27. 27. • NoSQL • MongoDB • MongoMapper •
  28. 28. MongoMapper http://github.com/jnunemaker/mongomapper
  29. 29. ActiveRecord API +
  30. 30. gem install mongo_mapper
  31. 31. class Cats include MongoMapper::Document key :name, String end
  32. 32. irb
  33. 33. class Cats include MongoMapper::Document key :name, String end
  34. 34. class Cats include MongoMapper::Document key :name, String end
  35. 35. class Cats include MongoMapper::Document key :name, String end
  36. 36. irb:001:0> Cats.create :name => 'tama' irb:002:0> Cats.first => #<Cats name: "tama", _id: BSON::ObjectID('###')> irb:003:0> Cats.create :name => 'goro', :dapple_color => ‘gray’ irb:004:0> Cats.count => 2 irb:005:0> Cats.first(:name => ‘goro’) => #<Cats name: "goro", dapple_color:”gray”,_id: ###>
  37. 37. Array, Binary, Boolean, Date, Float, Hash Integer, Nil, ObjectId, Set, String, Time Custom Type, and TypeLess
  38. 38. Array, Binary, Boolean, Date, Float, Hash TypeLess Integer, Nil, ObjectId, Set, String, Time Custom Type, and TypeLess
  39. 39. class Storage include MongoMapper::Document key :value end
  40. 40. class Storage include MongoMapper::Document key :value end
  41. 41. irb:001:0> Storage.create :values => 25 irb:002:0> Storage.create :value => 'String' irb:003:0> Cats.all => [#<Storage value: 25, _id: BSON::ObjectID('###')>, #<Storage value: “String”, _id: BSON::ObjectID('###')>]
  42. 42. Array, Binary, Boolean, Date, Float, Hash Integer, Nil, ObjectId, Set, String, Time Custom Type, and TypeLess
  43. 43. class Family include MongoMapper::Document key :name, String many :cats end class Cats include MongoMapper::Document key :name, String key :family_id, ObjectId belongs_to :family end
  44. 44. class Person include MongoMapper::Document key :name, String one :address end class Address include MongoMapper::EmbeddedDocument key :zipcode, String key :street, String end
  45. 45. • validates_presence_of :title • validates_presence_of • validates_length_of • validates_format_of • validated_numericality_of • validates_acceptance_of • validated_configmati
  46. 46. class Cats include MongoMapper::Document key :name, String validates_presence_of :name end
  47. 47. class Cats include MongoMapper::Document key :name, String, :required => true end
  48. 48. class Cats include MongoMapper::Document key :name, String, :required => true end
  49. 49. before / after
  50. 50. validate, create, save
  51. 51. class Cats include MongoMapper::Document key :name, String before_validation :add_nyan private def add_nyan self.name += ‘ nyan’ end end
  52. 52. irb:001:0> Cats.create :name => 'tama' irb:002:0> Cats.first => #<Cats name: "tama nyan", _id: BSON::ObjectID('###')>
  53. 53. module Charisma def fly puts “I’m flying” end end MongoMapper::Document. append_inclusions(Charisma) Cats.first(:name => ‘tama’).fly
  54. 54. module Charisma def fly puts “I’m flying” end end MongoMapper::Document. append_inclusions(Charisma) Cats.first(:name => ‘tama’).fly
  55. 55. • NoSQL • MongoDB • MongoMapper •
  56. 56. MongoDB
  57. 57. DB KVS RDBMS
  58. 58. MongoMapper
  59. 59. ActiveRecord MongoDB
  60. 60. URL • http://www.mongodb.org/ • http://www.mongodb.org/display/DOCSJP/Home • http://wiki.github.com/jnunemaker/mongomapper/ • http://gihyo.jp/dev/serial/01/ruby/0033
  61. 61. by http://www.wanpug.com/

×