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.


  • rpc.statd goes wild!

    I came in to work today to find my mac workstation spinning running rpc.statd at 100% CPU. A quick dtruss -n rpc.statc showed that it was looping…

  • Useful Javascript

    I just created a drop-down menu with an option to add your own entries. Feel free to use. The skinny. Demo.

  • (no subject)

    I just asked my OpenSRS/Tucows domain reseller rep about AAAA (IPv6) glue records: They are planning to support them soon! In the mean time, they…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded