Basic SQL Interaction

Ruport offers direct SQL support via RubyDBI. Please be sure you have a working DBI installation before proceeding.

Setting your database login information

This is very similar to configuring DBI itself. Please see the Ruby/DBI website for complete details

Sample Configuration:

    Ruport::Query.add_source :default,
                             :user     => "sandal", 
                             :password => "blinky",
                             :dsn      => "dbi:mysql:testdb                       

You can specify multiple source databases by just using a name other than :default

Running a query directly and getting a Data::Table back

Slurping the whole table

  my_table = Ruport::Query.new("select * from foo").result # works everywhere

  my_table = query "select * from foo" # in the Report DSL only

Getting a Data::Table back from an SQL query stored in a file

Slurping the whole table

  my_table = Table("foo.sql") # works anywhere
  my_table = Ruport::Query.new("foo.sql").result # works anywhere  

  my_table = query "foo.sql" # in the Report DSL only

Advanced Features

Ruport also allows you to do:

  • Row-by-Row SQL processing
  • Parameter and ERb embedding in queries
  • Simple Caching
  • Enumerable processing of queries
  • raw result processing (DBI::Row objects)
  • other stuff

See the API Docs for details.

(note: anyone who wants to flesh out some examples here is welcome)