I have table devices
with models names:
+--------+-----------+
| models | id_number |
+--------+-----------+
| aaaaa | 11111 |
| bbbbb | 22222 |
| ccccc | 33333 |
| ddddd | 44444 |
+--------+-----------+
and I check whether the file path
contains the model
saved in the database:
/folder1/subfolder/filename_bbbbb_ver.zip
/folder1/filename_ddddd_ver.zip
/filename_aaaaa_ver.zip
for this I use this mysql query, which works very well:
sequelize.query("SELECT * FROM `devices` WHERE :path LIKE CONCAT('%\_',`models`, '\_%')",
{ replacements: { path: el.path_name} }
)
But now I want to rewrite above query to Sequelize “object” findAll, but I’m not sure that this is possible. Now I have like this:
const model_list = await devices.findAll({
where: {
[el.path_name]: { [Op.like]: sequelize.fn('%\_'+sequelize.col('models')+'\_%') }
}
})
But [el.path_name]
but treats it as a column name, not text.
1