- Added getAll route for spells with bookshelf

This commit is contained in:
Alexis
2020-05-27 21:26:35 +02:00
parent 48ee8cf08f
commit 1280d6ee1f
10 changed files with 139 additions and 89 deletions

View File

@@ -29,9 +29,9 @@ CREATE TABLE IF NOT EXISTS `school` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL DEFAULT "Nom de l'école",
`description` VARCHAR(255) DEFAULT "Description de l'école",
`id_meta_school` INT UNSIGNED NOT NULL,
`meta_school_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY(`id_meta_school`) REFERENCES meta_school(`id`)
FOREIGN KEY(`meta_school_id`) REFERENCES meta_school(`id`)
);
/* COMMON INGREDIENTS */
@@ -63,30 +63,30 @@ CREATE TABLE IF NOT EXISTS `user` (
/* SPELLS' SCHOOLS */
/* One spell can have multiple (up to 3) schools */
CREATE TABLE IF NOT EXISTS `spells_schools` (
`id_spell` INT UNSIGNED NOT NULL,
`id_school` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id_spell`, `id_school`),
FOREIGN KEY(`id_spell`) REFERENCES spell(`id`),
FOREIGN KEY(`id_school`) REFERENCES school(`id`)
CREATE TABLE IF NOT EXISTS `spell_school` (
`spell_id` INT UNSIGNED NOT NULL,
`school_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (`spell_id`, `school_id`),
FOREIGN KEY(`spell_id`) REFERENCES spell(`id`),
FOREIGN KEY(`school_id`) REFERENCES school(`id`)
);
/* SPELLS' VARIABLES */
/* One spell can have multiple (up to 2) variables of cost */
CREATE TABLE IF NOT EXISTS `spells_variables` (
`id_spell` INT UNSIGNED NOT NULL,
`id_variable` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id_spell`, `id_variable`),
FOREIGN KEY(`id_spell`) REFERENCES spell(`id`),
FOREIGN KEY(`id_variable`) REFERENCES variable(`id`)
CREATE TABLE IF NOT EXISTS `spell_variable` (
`spell_id` INT UNSIGNED NOT NULL,
`variable_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (`spell_id`, `variable_id`),
FOREIGN KEY(`spell_id`) REFERENCES spell(`id`),
FOREIGN KEY(`variable_id`) REFERENCES variable(`id`)
);
/* SPELLS' VARIABLES */
/* One spell can have multiple ingredients */
CREATE TABLE IF NOT EXISTS `spells_ingredients` (
`id_spell` INT UNSIGNED NOT NULL,
`id_ingredient` INT UNSIGNED NOT NULL,
PRIMARY KEY (`id_spell`, `id_ingredient`),
FOREIGN KEY(`id_spell`) REFERENCES spell(`id`),
FOREIGN KEY(`id_ingredient`) REFERENCES ingredient(`id`)
CREATE TABLE IF NOT EXISTS `spell_ingredient` (
`spell_id` INT UNSIGNED NOT NULL,
`ingredient_id` INT UNSIGNED NOT NULL,
PRIMARY KEY (`spell_id`, `ingredient_id`),
FOREIGN KEY(`spell_id`) REFERENCES spell(`id`),
FOREIGN KEY(`ingredient_id`) REFERENCES ingredient(`id`)
);

View File

@@ -12,7 +12,7 @@ INSERT INTO `meta_school` (name, description) VALUES
('Magies autres', 'Magies trop spécifiques et ne rentrant dans aucune autre grande école.');
-- SCHOOLS
INSERT INTO `school` (name, description, id_meta_school) VALUES
INSERT INTO `school` (name, description, meta_school_id) VALUES
('Lumomancie', 'Discipline arcanique de la lumière.', 1),
('Vitamancie', 'Discipline arcanique de la guérison et de l\'énergie vitale.', 1),
('Obstrumancie', 'Discipline arcanique de la protection et des sceaux.', 1),
@@ -223,11 +223,11 @@ SCHEMA
*/
DELIMITER $$
CREATE PROCEDURE insertIntoSchoolRange(IN delimiter_start INT, IN delimiter_end INT, IN school_id INT)
CREATE PROCEDURE insertIntoSchoolRange(IN delimiter_start INT, IN delimiter_end INT, IN id_school INT)
BEGIN
SET @i = delimiter_start;
WHILE @i <= delimiter_end DO
INSERT INTO spells_schools (id_spell, id_school) VALUES (@i, school_id);
INSERT INTO spell_school (spell_id, school_id) VALUES (@i, id_school);
SET @i = @i + 1;
END WHILE;
END$$

View File

@@ -6,6 +6,20 @@ const mysql = require('mysql')
let credentials_data = fs.readFileSync('./database/credentials.json')
let credentials = JSON.parse(credentials_data)
// Setting up the database connection
const knex = require('knex')({
client: credentials.client,
connection: {
host : credentials.host,
user : credentials.user,
password : credentials.password,
database : credentials.database,
charset : credentials.charset
},
debug: true
})
const bookshelf = require('bookshelf')(knex)
const db = mysql.createConnection({
host: credentials.host,
user: credentials.user,
@@ -19,4 +33,4 @@ db.on('error', err => {
}
})
module.exports = { db }
module.exports = { db, bookshelf }