Skip to content

Batching individual updates #1400

Answered by North101
frankvollebregt asked this question in Q&A
Discussion options

You must be logged in to vote

This should work:

await batch((batch) {
      for (final tree in trees) {
        batch.update(
          apples,
          ApplesCompanion(treeUuid: Value(tree.treeUuid)),
          where: apples.treeId.equals(tree.treeId),
        );
      }
});

This would probably be even faster, though its SQL only (I don't think moor support UPDATE FROM):

UPDATE apples
SET
  tree_uuid = tree.tree_uuid
FROM trees
WHERE trees.tree_id = apples.tree_id

However, I think the better solution is to just remove apples.tree_id and instead get the tree_id from the trees table.

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@davidmartos96
Comment options

@frankvollebregt
Comment options

@frankvollebregt
Comment options

@frankvollebregt
Comment options

@davidmartos96
Comment options

Answer selected by frankvollebregt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants