Express with pg

pg

Objectives

  • Integrate the pg module into your app
  • Write SQL Queries against your Postgres database
  • Use data from your database to serve views
  • Collect data from views and put it into your database

What's  pg ?

pg

A node module that enables interaction with your PostgreSQL database

Sweet

Let's build an Express app and access our database

1. Build our database
CREATE DATABASE pgteas;

\c pgteas

CREATE TABLE teas (
    id serial PRIMARY KEY,
    name varchar(150),
    flavor varchar(150),
    in_stock bool
);

INSERT INTO teas (name, flavor, in_stock) VALUES ('green tea', 'greeny', TRUE);
INSERT INTO teas (name, flavor, in_stock) VALUES ('blue tea', 'blueish', false);
INSERT INTO teas (name, flavor, in_stock) VALUES ('red tea', 'reddish', TRUE);
INSERT INTO teas (name, flavor, in_stock) VALUES ('yellow tea', 'lemony', TRUE);
1. Build our database
2. Create Express app
1. Build our database
2. Create Express app
3. Connect app to database...?

Jump into your  node   environment

node
1. Build our database
2. Create Express app
3. Connect app to database!

Rendering data

Poetry

Requirements:

  • query
  • parameterized sql
  • res.local
  • Allude to the two different ways of passing data to your view

Gathering data

3-2-1

3 things you learned

2 things you found interesting

1 thing you want to review

Made with Slides.com