Does batch method run its statements in order? #974
-
In a batch I have await batch((batch) {
batch.insertAll(
employeeTypes,
[...],
);
batch.insertAll(
employee,
[...],
);
}); When inserting each Employee into the employee table, they have a foreign key constraint on the id of the employeeTypes table. Can I be sure that all employeeTypes will be inserted before employees are inserted, or do I have to create a new batch? Also, within a single Thanks! (First discussion!) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi, the order was undefined in older moor versions, but we now guarantee that batches run statements in the order in which they were issued (and we have tests for that!). This is also true for each row inside an
Note that, if you do final id = await currentAutoGeneratedId();
final batch = await batch(() {
// assume that rows start at id
}); There could be some interleaving between |
Beta Was this translation helpful? Give feedback.
Hi,
the order was undefined in older moor versions, but we now guarantee that batches run statements in the order in which they were issued (and we have tests for that!). This is also true for each row inside an
insertAll
call.I don't know the exact moor version where this was changed, but if you're on 3.4.0 you should be safe.
Note that, if you do
There could be some interleaving between
await currentAutoGeneratedId()
andawait batch()
if you run another insert concurrently. If you want to be safe, wrap the select and the batc…