Class: Ua::SQLite3Table

Inherits:
Object
  • Object
show all
Defined in:
lib/ua/uadb.rb

Instance Method Summary collapse

Constructor Details

#initialize(db, table) ⇒ SQLite3Table

Returns a new instance of SQLite3Table.



3
4
5
6
7
# File 'lib/ua/uadb.rb', line 3

def initialize(db, table)
   require 'SQLite3'
   @db, @table = db, table
   @database = ::SQLite3::Database.new(@db + ".db") 
end

Instance Method Details

#[](a) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ua/uadb.rb', line 9

def [](a)
case a
  when lambda{|x| Integer(x) rescue false}
   @database.execute "select * from #{@table} where id=?", a.to_i
 when Hash
   k = a.keys
   x = k.map{|name| "#{name} = ?"}.join(" and ")
   y = k.map{|name| a[name]}
   @database.execute "select * from #{@table} where " + x, y 
  end
end