Skip to content

Commit

Permalink
feature(create users table on elephant sql postgres):
Browse files Browse the repository at this point in the history
create users table on elephant sql postgres
[Starts 165404965]
  • Loading branch information
Cavdy committed Apr 17, 2019
1 parent b92dda9 commit d2fb976
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 25 deletions.
6 changes: 6 additions & 0 deletions .directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Dolphin]
Timestamp=2019,4,17,3,23,17
Version=4

[Settings]
HiddenFilesShown=true
39 changes: 29 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "banking web app",
"main": "app.js",
"scripts": {
"server": "DEBUG=querysuccess nodemon --exec babel-node ./server/v1/config/database.js",
"server": "DEBUG=query nodemon --exec babel-node ./server/v1/config/database.js",
"start": "node ./server/build/app.js",
"build": "babel -d ./server/build ./server/v1 -s",
"dev": "nodemon --exec babel-node ./server/v1/app.js",
Expand Down Expand Up @@ -44,6 +44,7 @@
"jsonwebtoken": "^8.5.0",
"mocha": "^6.1.3",
"pg": "^7.8.1",
"pg-connection-string": "^2.0.0",
"swagger-ui-express": "^4.0.2"
},
"devDependencies": {
Expand Down
27 changes: 13 additions & 14 deletions server/v1/config/database.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { Client } from 'pg';
import { Pool } from 'pg';
import debug from 'debug';
import dotenv from 'dotenv';
import { parse } from 'pg-connection-string';

dotenv.config();

const conString = process.env.DB_CONFIG;
const conString = parse(process.env.DB_CONFIG);

const client = new Client(conString);
const pool = new Pool(conString);

client.connect((err) => {
if (err) {
return debug('connecterror')('could not connect to postgres', err);
// async/await - check out a client
(async () => {
const client = await pool.connect();
try {
const res = await client.query('SELECT NOW() AS "theTime"');
debug('query')(res.rows[0].theTime);
} finally {
client.release();
}
client.query('SELECT NOW() AS "theTime"', (error, result) => {
if (error) {
return debug('queryerror')('error running query', err);
}
debug('querysuccess')(result.rows[0].theTime);
client.end();
});
});
})().catch(e => debug('query')(e.stack));
21 changes: 21 additions & 0 deletions server/v1/config/user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Users SQL query

-- create users table
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(80),
firstName VARCHAR(20),
lastName VARCHAR(20),
password VARCHAR(80),
type VARCHAR(10),
isAdmin BOOLEAN
);

-- select all from users table
SELECT * FROM "users" LIMIT 10

-- insert into users table
INSERT into "users" values($1), ['value']

-- update into users
update users

0 comments on commit d2fb976

Please sign in to comment.