Module: Db
- Included in:
- Entry
- Defined in:
- lib/db.rb
Class Method Summary collapse
Instance Method Summary collapse
- #ask(query, *args) ⇒ Object
- #db ⇒ Object
- #log(query, *args) ⇒ Object
- #row(query, *args) ⇒ Object
- #sql(query, *args, &block) ⇒ Object
Class Method Details
.database ⇒ Object
10 11 12 |
# File 'lib/db.rb', line 10 def self.database @database end |
.database=(database) ⇒ Object
6 7 8 |
# File 'lib/db.rb', line 6 def self.database=(database) @database = database end |
Instance Method Details
#ask(query, *args) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/db.rb', line 29 def ask(query, *args) log query, *args r = db.get_first_value(query, *args) return r if r return db.changes if query =~ /^\s*(DELETE|INSERT)\b/i end |
#db ⇒ Object
14 15 16 |
# File 'lib/db.rb', line 14 def db @db ||= SQLite3::Database.new(Db.database) end |
#log(query, *args) ⇒ Object
18 19 20 |
# File 'lib/db.rb', line 18 def log(query, *args) # STDERR.puts "[sqlite] #{query}" end |
#row(query, *args) ⇒ Object
36 37 38 39 |
# File 'lib/db.rb', line 36 def row(query, *args) log query, *args db.get_first_row(query, *args) end |
#sql(query, *args, &block) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/db.rb', line 22 def sql(query, *args, &block) log query, *args r = db.execute query, *args, &block return r if r return [ db.changes ] if query =~ /^\s*(DELETE|INSERT)\b/i end |