Class: DBConnection
- Inherits:
-
Object
- Object
- DBConnection
- Defined in:
- lib/db_connection.rb
Class Method Summary collapse
- .execute(*args) ⇒ Object
- .execute2(*args) ⇒ Object
- .instance ⇒ Object
- .last_insert_row_id ⇒ Object
- .open(db_file_name) ⇒ Object
- .reset ⇒ Object
Class Method Details
.execute(*args) ⇒ Object
28 29 30 31 |
# File 'lib/db_connection.rb', line 28 def self.execute(*args) instance.execute(*args) end |
.execute2(*args) ⇒ Object
33 34 35 36 |
# File 'lib/db_connection.rb', line 33 def self.execute2(*args) instance.execute2(*args) end |
.instance ⇒ Object
22 23 24 25 26 |
# File 'lib/db_connection.rb', line 22 def self.instance DBConnection.open(DB_FILE) if @db.nil? @db end |
.last_insert_row_id ⇒ Object
38 39 40 |
# File 'lib/db_connection.rb', line 38 def self.last_insert_row_id instance.last_insert_row_id end |
.open(db_file_name) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/db_connection.rb', line 4 def self.open(db_file_name) @db = SQLite3::Database.new(db_file_name) @db.results_as_hash = true @db.type_translation = true @db end |
.reset ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/db_connection.rb', line 12 def self.reset commands = [ "rm '#{DB_FILE}'", "cat '#{SQL_FILE}' | sqlite3 '#{DB_FILE}'" ] commands.each { |command| `#{command}` } DBConnection.open(DB_FILE) end |