Skip to content

Instantly share code, notes, and snippets.

@santanaG
Created July 9, 2022 16:14
Show Gist options
  • Save santanaG/3794f8dd2f7c34b3d2a7da93264547d7 to your computer and use it in GitHub Desktop.
Save santanaG/3794f8dd2f7c34b3d2a7da93264547d7 to your computer and use it in GitHub Desktop.
const userQ = 'SELECT `id` FROM `user` WHERE `email` = ?'
const permissionsQ = 'SELECT `id`, `name` FROM `permission` WHERE `user_id` = ?'
const getUserbyEmail = (connection, email) => connection
.queryAsync(userQ, [email])
.spread(user => user === undefined
? [{}, {}]
: Promise.all([user, connection.queryAsync(permissionsQ, [user.id])]))
.then(([user, permissions]) => ({ ...user, permissions }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment