-
-
Notifications
You must be signed in to change notification settings - Fork 2
JSON Sugars
Oxford Harrison edited this page Nov 9, 2024
·
16 revisions
// A basic query with JSON formatting
const result = await client.query(
`SELECT
name,
{ email, phone AS mobile } AS contact1,
[ email, phone ] AS contact2
FROM users`
);
console.log(result);
Console
[ { name: 'John Doe', contact1: { email: 'johndoed@example.com', mobile: '(555) 123-4567' }, contact2: [ 'johndoed@example.com', '(555) 123-4567' ] }, { name: 'Alice Blue', contact1: { email: 'aliceblue@example.com', mobile: '(888) 123-4567' }, contact2: [ 'aliceblue@example.com', '(888) 123-4567' ] } ]