-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(create users table on elephant sql postgres):
create users table on elephant sql postgres [Starts 165404965]
- Loading branch information
Showing
5 changed files
with
71 additions
and
25 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[Dolphin] | ||
Timestamp=2019,4,17,3,23,17 | ||
Version=4 | ||
|
||
[Settings] | ||
HiddenFilesShown=true |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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)); |
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,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 |