Created
April 27, 2020 05:11
-
-
Save repodevs/e708b4f25cf6a05ca632a0872e500a12 to your computer and use it in GitHub Desktop.
sequelize mapToModel example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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