Database: DB models as input for db

master
E. Almqvist 3 years ago
parent a00560ba45
commit f996a5ce96
  1. 5
      src/app.rb
  2. 5
      src/db_init.rb
  3. 10
      src/lib/database.rb

@ -46,6 +46,11 @@ end
# API stuff # API stuff
post "/user" do post "/user" do
# create user # create user
email = params[:email]
name = params[:name]
password = params[:password]
password_confirm = params[:password_confirm]
redirect "/login" redirect "/login"
end end

@ -1,6 +1,7 @@
require_relative "db_models.rb"
LOAD_TABLES = [ LOAD_TABLES = [
"User", User
"Role"
] ]
def db_init def db_init

@ -46,15 +46,15 @@ end
class Database # Database class class Database # Database class
attr_reader :name, :path attr_reader :name, :path
attr_accessor :tables attr_accessor :tables
def initialize(name, tables_names=[], db_path=DEFAULT_DB_PATH) def initialize(name, load_tables=[], db_path=DEFAULT_DB_PATH)
@name = name @name = name
@path = db_path @path = db_path
@tables = [] @tables = {}
# generate table objects # generate table objects
tables_names.each do |name| load_tables.each do |table_model|
tbl = Table.new(self, name) tblobj = table_model.new(self)
@tables << tbl @tables[tblobj.name.to_sym] = tblobj
end end
end end

Loading…
Cancel
Save