Created
November 6, 2020 14:53
-
-
Save CosmoAbdon/764da3d7296876f2cd1f7b7115faf363 to your computer and use it in GitHub Desktop.
Revisions
-
CosmoAbdon created this gist
Nov 6, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ const bulkUpdate = async (model, dataValues, conditional) => { const transformValue = (...values) => values.map((v) => JSON.stringify(v)); const checkValue = ([A, B]) => A === B; const promises = dataValues.map((value) => model.update({ ...value }, { where: { [conditional]: value[conditional] } }) ); const results = await Promise.all(promises); const size = results.filter((r) => checkValue(transformValue(r, [0]))).length; return size; }; export default bulkUpdate;