Skip to content

Instantly share code, notes, and snippets.

@repodevs
Created April 27, 2020 05:11
Show Gist options
  • Save repodevs/e708b4f25cf6a05ca632a0872e500a12 to your computer and use it in GitHub Desktop.
Save repodevs/e708b4f25cf6a05ca632a0872e500a12 to your computer and use it in GitHub Desktop.
sequelize mapToModel example
/**
* @param {UUID} sourceId An ID to find.
*
* @returns {Object} an single object instance of Sequelize Model.
*/
async function getMyTableData(sourceId) {
const sequelize = await this.hub.api('DbConnector', 'Sequelize');
const mytable = await sequelize
.query(`SELECT *
FROM "my_table_name"
WHERE metadata->>'source_id' = '${sourceId}'
ORDER BY created_at DESC
LIMIT 1;`,
{
plain: true, // true == return single record
model: sequelize.model('MyTableName'),
mapToModel: true
});
return mytable;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment