-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
41 lines (32 loc) · 821 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const { Client } = require("pg");
const bcrypt = require("bcrypt");
let DB_URI;
DB_URI = "postgresql:///jobly";
let db = new Client({
connectionString: DB_URI
});
db.connect();
db.query(`CREATE TABLE IF NOT EXISTS users(
username text,
password text,
email text,
name text,
isAdmin bool
)`);
async function makeAdmin() {
const admin = await db.query(`SELECT * FROM users WHERE username='admin' AND isAdmin=true`);
if(admin.rows.length==0)
db.query(`INSERT INTO users VALUES('admin', $1, '[email protected]', 'John Doe', true)`,
[await bcrypt.hash('smellyPassword', 12)])
}
makeAdmin();
db.query(`CREATE TABLE IF NOT EXISTS jobs(
id int,
title text,
company text,
description text,
salary float,
equity float,
posterUsername text
)`);
module.exports = db;