CREATE TABLE ingredients (_id integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, ingredient varchar(50) NOT NULL); //INSERT INTO ingredients(ingredient) VALUES ('salt') //INSERT INTO ingredients(ingredient) VALUES ('chicken')
CREATE TABLE recipes(_id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY, recipe VARCHAR(50), ingredient_id integer, CONSTRAINT fk_ingredient FOREIGN KEY(ingredient_id) REFERENCES ingredients(_id) ON DELETE SET NULL) //((think about on delete status)) //INSERT INTO recipes(ingredient) VALUES ('baked chicken')
CREATE TABLE requirements (_id integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, recipe_id INT, ingredient_id INT, CONSTRAINT fk_recipe FOREIGN KEY(recipe_id) REFERENCES recipes(_id) ON DELETE SET NULL, CONSTRAINT fk_ingredient FOREIGN KEY(ingredient_id) REFERENCES ingredients(_id) ON DELETE SET NULL); //INSERT INTO requirements(recipe_id, ingredient_id) VALUES ('salt')
/*
<title>fancy colors</title> Change my color: Lemon Tangerine Lime Grapefruit Lavender <script> window.onload = () => { const body = document.querySelector('body'); const menu = document.querySelector('#menu'); button.onClick = () => { const fruit = menu.value; fetch('/colors', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ fruit: fruit }), }) .then(res => res.json()) .then(data => { body.style.background = data.colors; }) .catch(err => console.log(err)) } } </script>*/