connected postgres to redis

master
Matthew Huntington 2 years ago
parent 7e3fc18ac0
commit 1e8452a383

@ -35,7 +35,6 @@ console.log('connected');
//const animal = await client.json.get('animal', '$')
//console.log(animal);
await client.disconnect();
import pg from 'pg'
@ -45,7 +44,21 @@ const pgClient = new Client({
})
await pgClient.connect()
const res = await pgClient.query('SELECT * FROM people')
console.log(res.rows) // Hello world!
const results = await pgClient.query('SELECT pets.*, people.first_name, people.last_name, people.age AS owner_age FROM pets JOIN people ON pets.owner_id = pets.id')
const fluffy = {
id: results.rows[0].id,
name:results.rows[0].name,
species:results.rows[0].species,
age: results.rows[0].age,
owner: {
id:results.rows[0].owner_id,
first_name:results.rows[0].first_name,
last_name:results.rows[0].last_name,
age:results.rows[0].owner_age
}
}
console.log(fluffy);
await client.json.set('fluffy', '$', fluffy)
await pgClient.end()
await client.disconnect();

Loading…
Cancel
Save