Learning CouchDB for a SQL educated person is sometimes a bit tricky because things are solved so different. So happened to me.
Currently I am trying to create a simple invoicing app based on CouchDB. When creating invoices you might want to have a straight integer sequence to acts as invoice numbers. In a RDBM this is a great job to use an auto increment, auto value or DB sequence.
The CouchDB FAQ says that using sequences to identify records is not necessary because CouchDB has its own way to create document uuids and optimistically postulates that you’ll find a different way for all other DB-sequence use cases as well.
And well, I did :-)
Using an integer attribute “nr” for each invoice containing its number its as simple as creating a map-reduce-maximum-search to simulate a sequence:
View function:
The map function simply emits the invoice’s nr resulting into an array of invoice numbers.
Emit function:
The corresponding reduce method is also simple as pie. Just take the incoming array and look for and return the largest element. A simple maximum search.
My first idea of incrementing the return value by 1 to not only get the maximum invoice nr but also receive the next invoice number turned out to be a bad idea.
This is because the reduce function can be called multiple times. Those rereduce method calls then fold result values of prio reduce-calls.
Example:
[1,4,2,5,6,3] might be split into [1,4,2] and [5,6,3].
[1,4,2] reduces to 4.
[5,6,3] reduces to 6,
[4,6] then finally reduces to 6.
Since we don’t know when we’re in the last map invocation we pass the job to increment the result of the maximum search to the client.
Using couch_potato in a Ruby app the example looks like this:
When starting to work with CouchDB the lack of an indepth documentation can be a bit frustrating.
If you’re wondering where JavaScript methods like “sum” used in reduce functions are described, for example, you don’t find any detailed information in the CouchDB-Wiki.
What you can do is to have a look at:
COUCHDB_HOME/share/server
There are a number of javascript files.
They contain the method definitions you’re looking for.
For my version of CouchDB (0.10.1) there is a single .js file called main.js containing the sum function definition:
In newer CouchDB versions such as 0.11.0 you’ll find multiple javascript files. Just have look at them.
When trying to create a rails project you might encounter the following error:
/Users/jfischer/.rvm/gems/ruby-1.9.1-p378/gems/rails-3.0.0.beta3/bin/rails:1:in `require’: no such file to load — rails/cli (LoadError)
from /Users/jfischer/.rvm/gems/ruby-1.9.1-p378/gems/rails-3.0.0.beta3/bin/rails:1:in `<top (required)>’
from /Users/jfischer/.rvm/gems/ruby-1.9.1-p378/bin/rails:19:in `load’
from /Users/jfischer/.rvm/gems/ruby-1.9.1-p378/bin/rails:19:in `<main>’
The problem can be solved by uninstalling all prior rails and active* beta versions using the gem command:
If you encounter an error like the following when trying to install rails 3 prerelease:
ravel:~ jfischer$ gem install rails --prerelease
Successfully installed rails-3.0.0.beta3
1 gem installed
Installing ri documentation for rails-3.0.0.beta3...
ERROR: While executing gem ... (Errno::ENOENT)
No such file or directory - lib
then you might want to try skipping the ri and rdoc generation which worked for me:
Really impressed by the beauty of scottish architecture I was wondering how the Scottish Ruby Conference will be like.It has been held at the Royal College of Physicians in Edinburgh a really impressive location. With a history of more than 300 (!) years it is an organization contrasting the the baby aged computer science fraction.
The contrast of talks delivering bleeding edge content and rooms like the “old library” with the elegance and beauty of centuries made up an extraordinary atmosphere.
It was great to see so many well known faces in Edinburgh. I’ve met friends from many different places such as Berlin, Belgium, and the Netherlands. It’s always a pleasure to hang out with you guys!
The talks have been on a very good level.Beside Jim Weirich’s role playing talk about Rails and the ENTERPRISE (sound like “the Beauty and the Beast”, I Know) I really liked Elise Huard’s talk “12 hours to rate a rails application“. This talk covered - beside others - how to use code metrics to find code smells, how those metrics work and which social aspect to keep in mind when interviewing the programming team of the app to be evaluated.
Certainly a highlight was the insight view of scottish culture with music a weapon fights. Have a look at scotruby’s flickr photos and see them in action. Awesome!
It was also very nice to hang out with a lot of new people in various situations. I really hope we’ll see next year at the Scottish Ruby Conference 2011!
If you ever have to print a document from a Ruby app you might want to consider using JRuby to access the Java Printing API.Here is a small example accessing the API, looking up the printers and printing out their names to the console:
The RuPy conference 2009 was really a great event. I was totally excited how a polish technology conference will look like and I was impressed how the organiziers cared about everything. Among others Jakub P. Nowak, Katarzyna Bylec and Adam Parchimowicz helped with any open questions. They organized a hotel room as well as the transportation from and to the airport. That’s really a great thing for a non-commercial conf!
The conference itself was a hell lot of fun with very good speakers and valuable talks.
I enjoyed hanging around with Charles Nutter aka headius. I am totally impressed by his work for JRuby and his very smart and analytic way of thinking. His talk about JRuby without any slides was very motivating and helped me to find my enthusiasm for live coding sessions.
Another talk that souldn’t be missing on a good conference is Paolo Negri presenting RabbitMQ. I heard his talks before at RailsConf 2009 in Las Vegas and Rails Underground 2009 in London. They are never the same and always worth listening to them. Even multiple times.
Michael Dirolf’s talk An Introduction to MongoDB was very interesting. I really like MongoDB because it’s a document based DB with a query language that is very easy to understand for people with RDBMS experience. So have a look at it.
And of course don’t miss Eleanor McHugh. Her talk The Ruby Plumber’s Guide to *nix was very contrasting to other talks. She adviced people to remind that web applications are not aliens landed on a unix box but that they are still living in a symbiotic way with it. I think if you have a question about system programming - ask her! Don’t excpect a single sentence answer but be sure you will get a very profound one.
Serge Smetana presented Advanced Performance Optimization of Rails Applications. Badly I was unable to listen to his talk but everybody said it was very, very good. We talked a lot so I am totally sure that he really knows about optimization very well.
I have received a lot positive feedback for my own talk about Ruby and Python Enterprise Hosting as well. Thanks to everybody for that. I still think that people can save a lot of time, nerves and money if they really gather their requirements before diving into the hosting topic. I tried to sum up the most important factors when building a high availability hosting platform. So if you have any questions about this - just let me know.
Beside the conference content there were a lot of great off topic conversations with many people. I totally liked hanging around with Chares, Michael, Serge, Elenor, Paolo and all the others. Hope to see these friends again, soon. Maybe on the next conf, maybe on the next RuPy?
P.S.: I heard about wedding crashers before. This time I saw my first conference crasher. There was this guy who found (or stolen) a conference batch. He used it to get free food and attended to a number of talks. Instead of beeing calm he talked to nearly every speaker. It turned out that he doesn’t have a clue what Ruby or Python is. At the end of the conf he told one of the organizers that he is actually not a legitimate attende. The orga team told him they will call the police. I saw the ANGST in his eyes :-) Mabe that’s what he needed after behaving very very odd and unpolite in many situations. However he was another fun factory for the conf!