Skip to main content

MonetDB's Ruby API

MonetDB has a Ruby connector in its collection of supported clients since 2008. Recently we have begun to further improve  this client and made it compatible with Ruby versions 2.0 and above. These improvements are already part of the Jul2015-SP2 release.

The next step is to modernize the MonetDB/Ruby support and improve its ease of use. In the coming MonetDB feature release (planned in Apr. 2016, at the time of this writing), you can expect the following new features:

  1. Several internal iterator methods have been added to help you iterate over the query results. Displaying results is now as simple as typing:

        result = db.query("SELECT * FROM my_table")
        result.each_record { |record| puts record }

    The internal iterators are more in line with the Ruby conventions and may be preferable to use. The external iterator, which is used by repeatedly calling the fetch method, remains available. However, a reset_index method has been added to allow you to iterate over the result set multiple times without having to rerun the query.

  2. The connector  automatically returns its results in the matching Ruby types, e.g., a date in the database will be converted to a Date object in Ruby. This applies to the built-in and temporal data types in MonetDB. They are converted to Ruby objects, e.g., Float, Int, Date, Time and DateTime, accordingly.

We will also extend MonetDB's SQL Reference Manual with information for the Ruby language binding. But for now, you can find more information on the improved interface in the new example.rb file in the default branch of the MonetDB Mercurial repository.