NoSQL を Ruby で実践するための n 個の方法
Upcoming SlideShare
Loading in...5
×
 

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

on

  • 7,320 views

 

Statistics

Views

Total Views
7,320
Views on SlideShare
7,008
Embed Views
312

Actions

Likes
8
Downloads
39
Comments
1

5 Embeds 312

http://d.hatena.ne.jp 288
url_unknown 13
http://mahito.hatenablog.com 9
http://paper.li 1
http://a0.twimg.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

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

  • 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.find() { "_id" : ObjectId("4c49118783d1600c126d2147"), "name" : "tama" } { "_id" : ObjectId("4c49119983d1600c126d2148"), "name" : "goro", "dapple_color" : "gray" }
  • • 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) • • Index • • in-place • large objects ( ) • • sharding • MapReduce •
  • ≒ ≒
  • { "_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> 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: ###>
  • 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 Type, and TypeLess
  • 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 value: 25, _id: BSON::ObjectID('###')>, #<Storage value: “String”, _id: BSON::ObjectID('###')>]
  • 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::Document key :name, String key :family_id, ObjectId belongs_to :family end
  • class Person include MongoMapper::Document key :name, String one :address end class Address include MongoMapper::EmbeddedDocument key :zipcode, String key :street, String end
  • • validates_presence_of :title • validates_presence_of • validates_length_of • validates_format_of • validated_numericality_of • validates_acceptance_of • validated_configmati
  • 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 self.name += ‘ nyan’ end end
  • 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.first(:name => ‘tama’).fly
  • module Charisma def fly puts “I’m flying” end end MongoMapper::Document. append_inclusions(Charisma) Cats.first(:name => ‘tama’).fly
  • • 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/mongomapper/ • http://gihyo.jp/dev/serial/01/ruby/0033
  • by http://www.wanpug.com/