dynamo-easy icon indicating copy to clipboard operation
dynamo-easy copied to clipboard

Batch Write with empty array

Open fredspivock opened this issue 5 years ago • 2 comments

I need to check if my array is empty before doing a batch write

Would be nice if it just ignored empty arrays.

(also handling batch over 25 would be amazing)

Thanks!

fredspivock avatar Jul 10 '20 01:07 fredspivock

Hey @fredspivock ,

Do you have some example code?

itsdarrylnorris avatar Jul 14 '20 09:07 itsdarrylnorris

Here is an example, I have to check if they are empty before adding them to a batchwrite, if the array is empty it will error. I want it to ignore empty arrays would remove my need to do this check.

try {
        let questionStoreInstance = questionStore.batchWrite();
        if (questionsToDelete.length !== 0) {
            questionStoreInstance = questionStoreInstance.delete(questionsToDelete);
        }

        if ((questionsToCreate.length + questionsToUpdate.length) !== 0) {
            questionStoreInstance = questionStoreInstance.put([...questionsToCreate, ...questionsToUpdate])
        }

        await questionStoreInstance.exec();
    } catch (e) {
        logger.error(`Cannot update questions: ${e}`);
        return buildReturnBody(e);
    }

fredspivock avatar Jul 25 '20 04:07 fredspivock