Class: RDBI::Result::Driver::CSV
- Inherits:
-
RDBI::Result::Driver
- Object
- RDBI::Result::Driver
- RDBI::Result::Driver::CSV
- Defined in:
- lib/rdbi/result.rb
Overview
This driver yields CSV:
dbh.execute("select foo, bar from my_table").fetch(:first, :CSV)
Yields the contents of columns foo and bar in CSV format (a String).
The fastercsv
gem on 1.8 is used, which is the canonical csv
library on 1.9. If you are using Ruby 1.8 and do not have this gem available and try to use this driver, the code will abort during driver construction.
Instance Method Summary collapse
- #format_multiple_rows(raw_rows) ⇒ Object
- #format_single_row(raw) ⇒ Object
-
#initialize(result, *args) ⇒ CSV
constructor
A new instance of CSV.
Constructor Details
#initialize(result, *args) ⇒ CSV
Returns a new instance of CSV.
388 389 390 391 392 393 394 395 396 |
# File 'lib/rdbi/result.rb', line 388 def initialize(result, *args) super if RUBY_VERSION =~ /^1.8/ RDBI::Util.optional_require('fastercsv') else require 'csv' end # FIXME columns from schema deal maybe? end |
Instance Method Details
#format_multiple_rows(raw_rows) ⇒ Object
402 403 404 |
# File 'lib/rdbi/result.rb', line 402 def format_multiple_rows(raw_rows) raw_rows.inject("") do |accum, row| accum << row.to_csv end end |
#format_single_row(raw) ⇒ Object
398 399 400 |
# File 'lib/rdbi/result.rb', line 398 def format_single_row(raw) raw.to_csv end |