Class: Wlog::DbRegistry
- Inherits:
-
Object
- Object
- Wlog::DbRegistry
- Includes:
- StaticConfigurations
- Defined in:
- lib/wlog/db_registry.rb
Overview
Constant Summary
Constants included from StaticConfigurations
StaticConfigurations::AppDirectory, StaticConfigurations::AppName, StaticConfigurations::ConfigDirectory, StaticConfigurations::ConfigFile, StaticConfigurations::DataDirectory, StaticConfigurations::DefaultDb, StaticConfigurations::TaintFile, StaticConfigurations::TemplateDir
Instance Attribute Summary collapse
-
#handle ⇒ Object
the database handle.
Instance Method Summary collapse
-
#execute(*sql) ⇒ Object
execute a sql with varargs parameters.
-
#initialize(dbname) ⇒ DbRegistry
constructor
A new instance of DbRegistry.
-
#last_row_from(tablename) ⇒ Object
Get the last row, given a table name.
Constructor Details
#initialize(dbname) ⇒ DbRegistry
Returns a new instance of DbRegistry.
12 13 14 |
# File 'lib/wlog/db_registry.rb', line 12 def initialize(dbname) @handle = SQLite3::Database.new(dbname || "#{DataDirectory}#{ARGV[0] || DefaultDb}") end |
Instance Attribute Details
#handle ⇒ Object
the database handle
33 34 35 |
# File 'lib/wlog/db_registry.rb', line 33 def handle @handle end |
Instance Method Details
#execute(*sql) ⇒ Object
execute a sql with varargs parameters
21 22 23 |
# File 'lib/wlog/db_registry.rb', line 21 def execute(*sql) @handle.execute(*sql) end |
#last_row_from(tablename) ⇒ Object
Get the last row, given a table name. The table needs to have an id
26 27 28 29 30 |
# File 'lib/wlog/db_registry.rb', line 26 def last_row_from(tablename) query = "SELECT * FROM #{tablename} WHERE id =(SELECT MAX(id) FROM"\ " #{tablename});" @handle.execute(query) end |