Skip to content

Instantly share code, notes, and snippets.

@sergeysova
Forked from TheRadioGuy/duck.js
Last active December 13, 2017 15:53
Show Gist options
  • Select an option

  • Save sergeysova/cd6f988d62af491d0ce6949fa4b562f4 to your computer and use it in GitHub Desktop.

Select an option

Save sergeysova/cd6f988d62af491d0ce6949fa4b562f4 to your computer and use it in GitHub Desktop.
NodeJS
async function getMessages(login, loginMy) {
if (!login || !loginMy) {
throw new TypeError('param login and loginMy should be present');
}
const resp = await connection.query(`SELECT * FROM messages WHERE fromU = '${login}' AND toU = '${loginMy}' UNION SELECT * FROM messages WHERE fromU = '${loginMy}' AND toU = '${login}' ORDER BY date DESC`);
return resp.map(value => Object.assign({
from: value.fromU,
to: value.toU,
}, value, { fromU: undefined, toU: undefined }))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment