-
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.
- Loading branch information
Raymond Fallon
committed
May 17, 2024
1 parent
edd9638
commit 98667d7
Showing
2 changed files
with
37 additions
and
0 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
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,29 @@ | ||
const { Client } = require('pg'); | ||
|
||
const pgclient = new Client({ | ||
host: process.env.POSTGRES_HOST, | ||
port: process.env.POSTGRES_PORT, | ||
user: 'postgres', | ||
password: 'postgres', | ||
database: 'postgres' | ||
}); | ||
|
||
pgclient.connect(); | ||
|
||
const table = 'CREATE TABLE student(id SERIAL PRIMARY KEY, firstName VARCHAR(40) NOT NULL, lastName VARCHAR(40) NOT NULL, age INT, address VARCHAR(80), email VARCHAR(40))' | ||
const text = 'INSERT INTO student(firstname, lastname, age, address, email) VALUES($1, $2, $3, $4, $5) RETURNING *' | ||
const values = ['Mona the', 'Octocat', 9, '88 Colin P Kelly Jr St, San Francisco, CA 94107, United States', 'octocat@github.com'] | ||
|
||
pgclient.query(table, (err, res) => { | ||
if (err) throw err | ||
}); | ||
|
||
pgclient.query(text, values, (err, res) => { | ||
if (err) throw err | ||
}); | ||
|
||
pgclient.query('SELECT * FROM student', (err, res) => { | ||
if (err) throw err | ||
console.log(err, res.rows) // Print the data in student table | ||
pgclient.end() | ||
}); |