pg-promise
just a little playground for pg-promise with a local PostgreSQL database.
Following the recording of a bootcamp session, you can find the video: here, made by Corey Ladovsky
videos
How to start
git clone git@github.com:AlexisRoe/pg-promise.git
cd pg-promise
npm install
create a .env.json file
{
"DEFAULT_PORT": 3000,
"CONFIG": {
"USER": "username",
"PASSWORD": "password",
"HOST": "localhost",
"PORT": 5432,
"DATABASE": "grovers_groomers",
"MAX": 30
},
"RECONNECT": {
"TRIES": 10,
"TIMETOWAIT": 5000,
"LISTENER": 1000
}
}
create the database using the schema
\i < userPath > /pg-promise/bd / schema.sql;
starting the backend
npm run dev
database schema
source: https://github.com/joinpursuit/6.4-lecture-notes/blob/master/UNIT3/introToSQLTables/schema.sql
DROP DATABASE IF EXISTS grovers_groomers;
CREATE DATABASE grovers_groomers;
\c grovers_groomers;
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS pets;
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
age INTEGER
);
CREATE TABLE pets (
id SERIAL PRIMARY KEY,
name TEXT,
species TEXT,
age INTEGER,
owner_id INT REFERENCES users(id) ON DELETE SET NULL
);
INSERT INTO users (name, age)
VALUES ('corsky', 100),
('jon', 26),
('jhenya', 21),
('celine', 29),
('jerry', 69);
INSERT INTO pets (name, species, age, owner_id)
VALUES ('Noboru', 'Cat', 14, 1),
('Hatchi', 'Cat', 10, 1),
('Snowball', 'Cat', 12, 3),
('Gruffy', 'Dog', 6, 2),
('Coco', 'Dog', 3, 5),
('Rosco', 'Cat', 19, NULL);