DisWarden/lib/database_manager.rb

27 lines
648 B
Ruby
Raw Permalink Normal View History

2024-02-11 10:37:35 -07:00
# 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
2024-02-11 10:37:35 -07:00
end