CouchDB is a RESTful JSON eating beast of a document-oriented database. It is great for a lot of things, but traditional databases are a better choice in other places. DataMapper removes the need to choose by allowing easy integration of multiple databases in a single Merb app. I will explain the pros/cons of using CouchDB and show where it excels and when you can fall back to a regular database.
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Multiple Databases with Merb
1. Using Multiple
Databases in Merb
With special guest CouchDB
Wesley Beary | Software Engineer
wesley@plinky.com
2. DataMapper!
• database.yml maps first connection to
the :default repository.
• database.yml is a hash, each
environment can have many keys.
• Assign the primary database to
the :default key and other databases to
distinct meaningful keys (or not).
Wesley Beary | Software Engineer | wesley@plinky.com
3. # TODO: use them?
• run a specific command:
repository(:key) { some_command(s) }
or
Foo.all(:repository => repository(:key))
• set a model’s storage location:
class Bar
def self.default_repository_name
:key
end
end
Wesley Beary | Software Engineer | wesley@plinky.com
4. Dear Sir or Madam,
Why should I care?
Thanks,
The Audience
Wesley Beary | Software Engineer | wesley@plinky.com
8. How about a use case?
Muddle: merb + couchdb == tumblelog
Wesley Beary | Software Engineer | wesley@plinky.com
9. STI: Icky Tables
• Single table inheritance gets gross.
• Usually the fields for the parent and
every child go on EVERY record.
• CouchDB lets you store just what you
need on a case by case basis.
Wesley Beary | Software Engineer | wesley@plinky.com
10. Tumbling
• Each posts may have vastly different
content/fields from other posts.
• There are many different child classes
derived from Post.
• Some posts have associated files,
attachments help keep it organized.
Wesley Beary | Software Engineer | wesley@plinky.com
11. Random Posts
Wesley Beary | Software Engineer | wesley@plinky.com
14. Details?
• User data is safely stored in mysql.
• Files save and load from CouchDB.
• Mostly a proof of concept, needs work to
flesh out the details still.
• No load/performance testing just yet,
hard to say how production-worthy parts
might be.
Wesley Beary | Software Engineer | wesley@plinky.com
15. Caution Associations
Ahead
• define cross repository belongs
repository(:key) do
belongs_to :model
end
• define cross repository has
has n, :models, :repository => repository(:key)
Wesley Beary | Software Engineer | wesley@plinky.com
16. Play along at home!
http://github.com/monki/muddle
Wesley Beary | Software Engineer | wesley@plinky.com