27 lines
648 B
Ruby
27 lines
648 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'sequel'
|
|
|
|
DB = Sequel.sqlite(File.join(__dir__, '../db/diswarden.sqlite3'))
|
|
|
|
# Main class for handling Database ORM
|
|
class DatabaseManager
|
|
# TODO: Implement this properly to save hashes
|
|
def self.file_hash_exists?(hash)
|
|
DB[:scanned_files].where(file_hash: hash).count.positive?
|
|
end
|
|
|
|
def self.insert_file_hash(hash, is_safe)
|
|
DB[:scanned_files].insert(file_hash: hash, is_safe:)
|
|
end
|
|
|
|
def create_table
|
|
# Schema definition
|
|
DB.create_table? :scanned_files do
|
|
primary_key :id
|
|
String :file_hash, unique: true, null: false
|
|
Boolean :is_safe, default: true
|
|
end
|
|
end
|
|
end
|