Database: db_init & db_models stuff

master
E. Almqvist 3 years ago
parent 556c8e62fa
commit a00560ba45
  1. 8
      src/app.rb
  2. 8
      src/db_init.rb
  3. 3
      src/db_models.rb
  4. 2
      src/lib/database.rb
  5. 2
      src/sql/tables/Role.sql
  6. 2
      src/sql/tables/User.sql

@ -14,15 +14,11 @@ require_relative "debug.rb"
require_relative "lib/database.rb"
require_relative "func.rb"
require_relative "db_init.rb"
require_relative "db_models.rb"
load_tables = [
"User",
"Role"
]
db = Database.new("main", load_tables)
enable :sessions
db = db_init
def init_params(params={})
g = Hash.new ""

@ -0,0 +1,8 @@
LOAD_TABLES = [
"User",
"Role"
]
def db_init
db = Database.new("main", LOAD_TABLES)
end

@ -30,7 +30,8 @@ class User < Table
pw_hash: pw_hash
}
self.insert(@name, data) # insert into the db
resp = self.insert(@name, data) # insert into the db
return true, resp
else
return false, "Password mismatch!"
end

@ -8,9 +8,7 @@ class Table
@db = db
@name = name
@sql_file = "sql/tables/#{name}.sql"
end
def create_table
begin
q = File.read @sql_file # get SQL script
@db.query q # run query

@ -1,4 +1,4 @@
CREATE TABLE "Role" (
CREATE TABLE IF NOT EXISTS "Role" (
"id" INTEGER NOT NULL UNIQUE,
"name" TEXT NOT NULL,
"color" INTEGER NOT NULL DEFAULT 16777215,

@ -1,4 +1,4 @@
CREATE TABLE "User" (
CREATE TABLE IF NOT EXISTS "User" (
"id" INTEGER NOT NULL UNIQUE,
"email" TEXT NOT NULL UNIQUE,
"pw_hash" TEXT NOT NULL UNIQUE,

Loading…
Cancel
Save