Added Sequel ORM for database handling; added navbar

This commit is contained in:
2023-07-05 18:04:31 -04:00
parent 6f680e72e5
commit 6c1c8bca0a
16 changed files with 122 additions and 4 deletions

26
src/config.rb Normal file
View File

@ -0,0 +1,26 @@
require 'yaml'
class Config
DEFAULT_CONFIG = 'config/defaults.yaml'
def initialize(config_path)
@data = YAML::load_file(DEFAULT_CONFIG)
if File.exists?(config_path)
@data.merge!(YAML::load_file(config_path))
end
end
def get(key, depth = 0)
bits = key.split('.')
value = @data
bits.each do |bit|
value = value[bit]
end
return value
end
end

5
src/models/benchmark.rb Normal file
View File

@ -0,0 +1,5 @@
class Benchmark < Sequel::Model
one_to_many :results
end

5
src/models/hardware.rb Normal file
View File

@ -0,0 +1,5 @@
class Hardware < Sequel::Model(:hardware)
one_to_many :results
end

3
src/models/init.rb Normal file
View File

@ -0,0 +1,3 @@
require_relative 'hardware'
require_relative 'benchmark'
require_relative 'result'

6
src/models/result.rb Normal file
View File

@ -0,0 +1,6 @@
class Result < Sequel::Model
many_to_one :hardware
many_to_one :benchmarks
end

View File

@ -1,8 +1,10 @@
class GameData < Sinatra::Base
get '/' do
results = Result.reverse(:updated_at).limit(10).all()
erb :'index/index', locals: {
title: 'Test!!!',
results: []
title: 'Dashboard',
results: results
}
end

View File

@ -1,4 +1,11 @@
require 'sinatra/base'
require 'sequel'
require 'sqlite3'
# Load the Sequel timestamps plugin
Sequel::Model.plugin(:timestamps)
# Initialize Sequel gem for database actions
DB = Sequel.connect(adapter: $conf.get('database.adapter'), database: $conf.get('database.database'))
# Base app
class GameData < Sinatra::Base
@ -14,3 +21,5 @@ end
# Load routes
require_relative 'routes/init'
# Load models
require_relative 'models/init'