-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from swaibat/ch-Postgress-setup-166116575
#166116575 Setup postgresql and create User table
- Loading branch information
Showing
6 changed files
with
70 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.env | ||
node_modules | ||
package-lock.json | ||
.nyc_output | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pg from 'pg'; | ||
import dotenv from 'dotenv' | ||
dotenv.config() | ||
|
||
const config = { | ||
user: process.env.user, // this is the db user credential | ||
database:process.env.database, | ||
password: process.env.password, | ||
port: process.env.port, | ||
max: 10, // max number of clients in the pool | ||
idleTimeoutMillis: 30000, | ||
}; | ||
|
||
const pool = new pg.Pool(config); | ||
|
||
pool.on('connect', () => { | ||
}); | ||
|
||
const createTables = () => { | ||
const Users = `CREATE TABLE IF NOT EXISTS | ||
users ( | ||
id SERIAL PRIMARY KEY, | ||
firstName VARCHAR (128) NOT NULL, | ||
lastName VARCHAR(128) NOT NULL, | ||
address TEXT NOT NULL, | ||
email VARCHAR (355) UNIQUE NOT NULL, | ||
password VARCHAR(128) NOT NULL, | ||
status VARCHAR(128) NOT NULL, | ||
createdOn TIMESTAMP DEFAULT Now(), | ||
modifiedOn TIMESTAMP NOT NULL, | ||
isAdmin BOOLEAN NOT NULL | ||
)`; | ||
|
||
pool.query(Users) | ||
.then((res) => { | ||
return res; | ||
}) | ||
.catch((err) => { | ||
return err; | ||
}); | ||
}; | ||
|
||
pool.on('remove', () => { | ||
process.exit(0); | ||
}); | ||
|
||
|
||
// export pool and createTables to be accessible from an where within the application | ||
|
||
export { | ||
createTables, | ||
pool, | ||
} | ||
|
||
require('make-runnable'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,5 +58,4 @@ export class Loan { | |
loan.status = 'rejected'; | ||
res.status(200).send(loan); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters