Class: Bartleby::Connection
- Inherits:
-
Object
- Object
- Bartleby::Connection
- Defined in:
- lib/bartleby/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
27 28 29 30 |
# File 'lib/bartleby/connection.rb', line 27 def self.execute(*args) print_query(*args) instance.execute(*args) end |
.execute2(*args) ⇒ Object
32 33 34 35 |
# File 'lib/bartleby/connection.rb', line 32 def self.execute2(*args) print_query(*args) instance.execute2(*args) end |
.instance ⇒ Object
21 22 23 24 25 |
# File 'lib/bartleby/connection.rb', line 21 def self.instance reset if @db.nil? @db end |
.last_insert_row_id ⇒ Object
37 38 39 |
# File 'lib/bartleby/connection.rb', line 37 def self.last_insert_row_id instance.last_insert_row_id end |
.open(db_file_name) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/bartleby/connection.rb', line 5 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 |
# File 'lib/bartleby/connection.rb', line 12 def self.reset commands = [ "rm '#{db_file}'", "cat '#{seed_file}' | sqlite3 '#{db_file}'" ] commands.each { |command| `#{command}` } Connection.open(db_file) end |