require 'csv'
require 'sldb'

DB = SLDB::class :schema => 'create table t ( a, b, c )'
db = DB::new 'sldb'

#
# sldb uses arrayfields so many operations are natural since tuples are arrays,
# yet can be indexed by field
#
db.transaction do
  db.execute "insert into t values ( 'A', 'B', 'C' )"
  db.execute('select * from t') do |tuple| 
    puts "tuple => #{ tuple.inspect }"
    tuple.fields.each{|f| puts "  tuple[#{ f }] => #{ tuple[f] }"}
  end
end

puts

#
# csv generation is an example of something which is much more natural with
# arrays
#
CSV::generate('csv') do |csv|
  db.ro_transaction{db.execute('select * from t'){|t| csv << t}}
end
puts(IO::read('csv'))

