Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Batch Write with empty array #320

Open
fredspivock opened this issue Jul 10, 2020 · 2 comments
Open

Batch Write with empty array #320

fredspivock opened this issue Jul 10, 2020 · 2 comments

Comments

@fredspivock
Copy link

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!

@itsdarrylnorris
Copy link

Hey @fredspivock ,

Do you have some example code?

@fredspivock
Copy link
Author

fredspivock commented Jul 25, 2020

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);
    }

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants