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
post "/user" do
# create user
email = params[:email]
name = params[:name]
password = params[:password]
password_confirm = params[:password_confirm]
redirect "/login"
end

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

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

Loading…
Cancel
Save