From cbf9042fa8b87392b3cc4570084989e4be30a549 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 3 Feb 2022 10:39:34 +0100 Subject: [PATCH] Database class --- src/app.rb | 2 ++ src/database.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/database.rb diff --git a/src/app.rb b/src/app.rb index 4afeac0..c7dc02a 100755 --- a/src/app.rb +++ b/src/app.rb @@ -6,6 +6,8 @@ require "slim" require "sqlite3" require "sassc" +require_relative "database.rb" + def get_random_subtitle subtitles = File.readlines "misc/subtitles.txt" subtitles.sample.chomp diff --git a/src/database.rb b/src/database.rb new file mode 100644 index 0000000..99f7870 --- /dev/null +++ b/src/database.rb @@ -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