Database class

master
E. Almqvist 3 years ago
parent 38a83dfbfc
commit cbf9042fa8
  1. 2
      src/app.rb
  2. 15
      src/database.rb

@ -6,6 +6,8 @@ require "slim"
require "sqlite3" require "sqlite3"
require "sassc" require "sassc"
require_relative "database.rb"
def get_random_subtitle def get_random_subtitle
subtitles = File.readlines "misc/subtitles.txt" subtitles = File.readlines "misc/subtitles.txt"
subtitles.sample.chomp subtitles.sample.chomp

@ -0,0 +1,15 @@
DEFAULT_DB_PATH = "db/database.db"
class Database
attr_reader :name, :db_path
def initialize(name, db_path=DEFAULT_DB_PATH)
@name = name
@db_path = db_path
end
def get_handle
db = SQLite3::Database.new @db_path
db.results_as_hash = true
return db
end
end
Loading…
Cancel
Save