I use node.js and pg library (node-postgres) to interact with database.
This is the code I use to retrieve one user of specific ID:
const { rows: users } = await db.query("SELECT * FROM users WHERE id = $1", [id]);
const user = users[0];
Even if there is only one record postgres always returns an array, so I retrieve this first item in the second line.
Is there a way to shorten this code if there is only one user? Like make it one line instead of two.