#1 2026-04-22 14:13:31

Reco
Member
Registered: 2025-08-27
Posts: 1

TRestBatch multi-table atomic transaction

Hello,

I am using mORMot 2 with SQLite3 and I need to perform 3 operations
atomically across different ORM classes:
  - Add() to TInvoice
  - Update() to TSupplier 
  - Add() to TShipment

I am using TRestBatch with nil class like this:

  Batch := TRestBatch.Create(Rest.ORM, nil, 0);
  Batch.Add(InvoiceItem, True);
  Batch.Update(SupplierRec);
  Batch.Add(ShipmentItem, True);
  Rest.ORM.BatchSend(Batch);

My questions:
1. Is TRestBatch with nil class truly atomic across multiple tables?
2. Does BatchSend wrap everything in a single SQLite BEGIN/COMMIT transaction?
3. How long does it lock the DB for other concurrent users?
4. Is there a better approach for multi-table all-or-nothing operations?

Thank you

Offline

#2 2026-04-23 11:58:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,452
Website

Re: TRestBatch multi-table atomic transaction

The whole batch execution is protected by a global lock, and a single transaction.
If you group writes per class, it would be faster on most DB because the ORM would use multi-insert/update statements.

Offline

Board footer

Powered by FluxBB