Class: ASeriesOfTubes::TubeRecord::DBConnection
- Inherits:
-
Object
- Object
- ASeriesOfTubes::TubeRecord::DBConnection
- Defined in:
- lib/a_series_of_tubes/tube_record/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
30 31 32 33 |
# File 'lib/a_series_of_tubes/tube_record/db_connection.rb', line 30 def self.execute(*args) print_query(*args) instance.execute(*args) end |
.execute2(*args) ⇒ Object
35 36 37 38 |
# File 'lib/a_series_of_tubes/tube_record/db_connection.rb', line 35 def self.execute2(*args) print_query(*args) instance.execute2(*args) end |
.instance ⇒ Object
24 25 26 27 28 |
# File 'lib/a_series_of_tubes/tube_record/db_connection.rb', line 24 def self.instance reset if @db.nil? @db end |
.last_insert_row_id ⇒ Object
40 41 42 |
# File 'lib/a_series_of_tubes/tube_record/db_connection.rb', line 40 def self.last_insert_row_id instance.last_insert_row_id end |
.open(db_file_name) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/a_series_of_tubes/tube_record/db_connection.rb', line 6 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
14 15 16 17 18 19 20 21 22 |
# File 'lib/a_series_of_tubes/tube_record/db_connection.rb', line 14 def self.reset commands = [ "rm '#{TUBE_DB_FILE}'", "cat '#{TUBE_SQL_FILE}' | sqlite3 '#{TUBE_DB_FILE}'" ] commands.each { |command| `#{command}` } DBConnection.open(TUBE_DB_FILE) end |