DISQUS

DISQUS Hello!  The comments on this profile are unclaimed and thus are unverified.

Do they belong to you? Claim these comments.

lobo_tuerto's picture

Unregistered

Feeds

aliases

  • lobo_tuerto
  • lobo_tuerto

lobo_tuerto

3 days ago

in SQL Databases Are An Overapplied Solution (And What To Use Instead) on Adam @ Heroku
Hey Adam,

Sorry if this is a truly newbie question, I'm trying to wrap my head around something like CouchDB.

Let's take a concrete example, invoices and line items. An invoice can have many line items in it.

With a "normal" SQL DB, you would have two tables, say: Invoices, LineItems. And we all know how that works.
With a "document oriented" DB you would have Invoice docs, those docs, would directly contain the line items in them, right?

Is it possible (and/or easy) to do a query to get a report on the best selling line items? how do you work that on CouchDB? since they are all contained within Invoice documents... in a SQL DB you would only run a query on the LineItems table.

Does this question make sense? :)
1 reply
Jesse Hallett's picture
Jesse Hallett To calculate best selling line items with CouchDB you would create an index using line item ids as keys. You can use a map function to scan through every invoice document and emit each line item's id as a key. You can also create a reduce function to perform an aggregate operation on that index, like calculating the sum of all purchased line item quantities. Finally you pass a query to that map/reduce pair with a key parameter specifying that CouchDB should only aggregate quantities from line items with the given id.

There are instructions online for doing this stuff:
http://www.google.com/search?ie=UTF-8&oe=UTF-8&...
http://sitr.us/2009/06/30/database-queries-the-...

9 months ago

in Building a Space Strategy Game with Ruby on Rails - Part I on Building Browsergames
Hi, great article! I'm looking forward to learn about how are you going to implement the automated tick process. cron job maybe?

I didn't know you had another side covering the same articles :)
http://www.mnkyx.com/dev/
Returning? Login