Aria Stewart (aredridel) wrote,
Aria Stewart

Database interfaces in Ruby are a little off, if you ask me; they’re as usable as PHP’s, for sure (which are really just raw API for whatever database you use, unless you use ADODB), but I expect more out of Ruby’s.

First off, I expect libraries to use basic data structures whenever possible. People are used to them. If there’s no reason to have your own class of stuff, don’t.

From DBI, I would expect queries to return a hash, with fields either being a string as a key, and value as the natural basic Ruby type for whatever type the field is: text, varchar and char fields should be Strings. int I would expect to be a Fixnum.

I expect all the fields in the query to be in the hash, even if the fields are null — given fields foo and bar, with bar being null in this row, I would expect the hash to contain { :foo => "foodata", :bar => nil }.

Using hashes, it's possible to create tuples for update with a little addition to the Hash class, like so:

class Hash def import(other) each_key do |k| self[k] = other[k] if other[k] end end end

That would update the hash with just new values; if HTTP POST parameters are also handled as a hash, that makes merging data from the web into the database as painless as data.import request.query.


  • (no subject)

    You do occasionally visit Boston Public Library, yes? If not, get on it! You were raised in and on libraries. They are in your blood! You…

  • (no subject)

    "I had never been in a room of people who were going to say 'yes' to me before." My friend and I crammed into a rush hour crowded train…

  • Recipe: Storm in the Garden

    Recipe: Storm in the Garden Ingredients 10 ml lavender vodka 10 ml orange vodka 10 ml hibiscus vodka 200 ml ginger ale ice…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded