Forum: Ruby DBrb 0.1.0

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
62002cee15efcf4628cd7efc19425a07?d=identicon&s=25 Tim Becker (Guest)
on 2006-05-27 13:45
(Received via mailing list)
I'm happy to announce the initial release of DBrb. DBrb is a minimal
database access API that's implemented as a wrapper around the DBI API.

I've written it because I'm to stupid to remember all the different ways
to access DBI, and found myself interspersing my scripts with naked SQL
statements during development, leaving them for later to figure out how
actually execute them after finishing the "Ruby" parts of my scripts.
DBrb reflects this style of programming.

Some Examples:

* Initializing the library:

  db ="my_dbi_driver_string", "usr", "credentials")

* Basic SELECT stuff:

  i = db.sql "select max(id) from some_table"
  first, last =  db.sql("SELECT first, last FROM some_name WHERE id =
?", 1000)

(a call to the method `sql` executes the sql statement and returns the
first row
returned by that call, or `nil`.)

* SELECT with a block:

  db.sql("SELECT first, last FROM some_name WHERE id < ?", 1000) do
    puts "#{row.first} #{row.last}"

(calling `sql` with a block iterates over all results returned by the
sql statement. The yielded row is a DBI::Row object extended to
respond to the names of the columns in the database. In case of
naming conflicts, you can still use `row[COLUMN_NAME]`)

* INSERT's, UPDATE's, etc. work the same;

  1.upto(1000) do |i|
        db.sql("INSERT INTO test_table (num) VALUES (?)", i)


This is an initial release, the main TODOs are implementing a
database indepedant way of handling transactions and creating
tests for different database backends.

The code necessary to implement this library is not very large or
complex. Yet I've found it to boost my productivity immensely,
expecially writing ad hoc scripts connecting to a database. I
hope it may turn out to be useful for others.

   -Tim Becker
This topic is locked and can not be replied to.