@ -35,7 +35,6 @@ console.log('connected');
//const animal = await client.json.get('animal', '$')
//const animal = await client.json.get('animal', '$')
//console.log(animal);
//console.log(animal);
await client . disconnect ( ) ;
import pg from 'pg'
import pg from 'pg'
@ -45,7 +44,21 @@ const pgClient = new Client({
} )
} )
await pgClient . connect ( )
await pgClient . connect ( )
const res = await pgClient . query ( 'SELECT * FROM people' )
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' )
console . log ( res . rows ) // Hello world!
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 pgClient . end ( )
await client . disconnect ( ) ;