Skip to content

Commit 24ac690

Browse files
committed
migrated to pg-promise
1 parent de7d553 commit 24ac690

10 files changed

Lines changed: 727 additions & 625 deletions

File tree

index.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,20 @@ const session = require('express-session');
1313
const flash = require('express-flash');
1414
const CategoryService = require('./services/category-service');
1515
const ProductService = require('./services/product-service');
16-
const pg = require("pg");
17-
const Pool = pg.Pool;
1816

19-
// should we use a SSL connection
17+
const pgp = require('pg-promise')();
18+
2019
let useSSL = false;
2120
let local = process.env.LOCAL || false;
2221
if (process.env.DATABASE_URL && !local){
2322
useSSL = true;
2423
}
25-
// which db connection to use
26-
const connectionString = process.env.DATABASE_URL || 'postgresql://localhost:5432/my_products';
24+
const connectionString = process.env.DATABASE_URL || 'postgresql://localhost:5432/my_products_list';
2725

28-
const pool = new Pool({
29-
connectionString,
30-
ssl : useSSL
31-
});
26+
const db = pgp(connectionString);
3227

33-
const categoryService = CategoryService(pool);
34-
const productService = ProductService(pool);
28+
const categoryService = CategoryService(db);
29+
const productService = ProductService(db);
3530
const categoryRoutes = Categories(categoryService);
3631
const categoryAPI = CategoriesAPI(categoryService);
3732
const productRoutes = Products(productService, categoryService);

0 commit comments

Comments
 (0)