Class: OpalORM::DBConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/opal_orm/db_connection.rb

Class Method Summary collapse

Class Method Details

.execute(*args) ⇒ Object



38
39
40
41
# File 'lib/opal_orm/db_connection.rb', line 38

def self.execute(*args)
  print_query(*args)
  instance.execute(*args)
end

.execute2(*args) ⇒ Object



43
44
45
46
# File 'lib/opal_orm/db_connection.rb', line 43

def self.execute2(*args)
  print_query(*args)
  instance.execute2(*args)
end

.instanceObject

def self.reset

commands = [
  "rm '#{CATS_DB_FILE}'",
  "cat '#{CATS_SQL_FILE}' | sqlite3 '#{CATS_DB_FILE}'"
]

commands.each { |command| `#{command}` }
DBConnection.open(CATS_DB_FILE)

end



30
31
32
33
34
35
36
# File 'lib/opal_orm/db_connection.rb', line 30

def self.instance
  if Util.get_database_path
    @db = open(Util.get_database_path)
  end

  @db
end

.last_insert_row_idObject



48
49
50
# File 'lib/opal_orm/db_connection.rb', line 48

def self.last_insert_row_id
  instance.last_insert_row_id
end

.open(db_file_name) ⇒ Object



13
14
15
16
17
18
# File 'lib/opal_orm/db_connection.rb', line 13

def self.open(db_file_name)
  @db = SQLite3::Database.new(db_file_name)
  @db.results_as_hash = true
  @db.type_translation = true
  @db
end