- App
git clone git@github.com:clusson/node-api-pg
cd node-api-pg
yarn install
- Postgre SQL
Windows
Get PostgreSQL
[postgresql](https://www.postgresql.org/download/windows/)
pg_ctl start
MacOS / Linux
brew install postgresql
brew services start postgresql
psql postgres
CREATE ROLE green_it WITH LOGIN PASSWORD 'p@ssword';
ALTER ROLE green_it CREATEDB;
CREATE DATABASE green_it;
GRANT ALL PRIVILEGES ON DATABASE green_it TO green_it;
psql -d greenit -U green_it
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE users (
userId uuid DEFAULT uuid_generate_v4(),
firstname varchar(25) NOT NULL,
lastname varchar(25) NOT NULL,
email varchar(50) NOT NULL,
created_at date NOT NULL DEFAULT NOW(),
roleId int NOT NULL,
PRIMARY KEY (userId),
FOREIGN KEY (roleId) REFERENCES roles(roleId)
);
CREATE TABLE roles (
roleId int NOT NULL,
role varchar(25) NOT NULL,
PRIMARY KEY (roleId)
);
CREATE INDEX "idx_users_email"
ON users ("email");
node index.js
- GET: curl http://localhost:3000/users
- POST: curl --data "name=Jerry&email=jerry@example.com" http://localhost:3000/users
- PUT: curl -X PUT -d "name=George" -d "email=george@example.com" http://localhost:3000/users/1
- DELETE: curl -X "DELETE" http://localhost:3000/users/1
social : cron financier : gain énergétique