Create, update and delete thousands of entity records in one call, writing only what changed.
Requires: OutSystems 11 (.NET) with SQL Server, Azure SQL, Oracle 12.1.0.2+, PostgreSQL or MySQL.
BulkMerge_Lib has one server action, BulkMerge. Pass it a list of records of any entity and it:
It all runs in the request's transaction.
RecordList
ToObject(YourList)
ToObject()
ModifiedAt, ModifiedBy
UpdatedRecords
The record lists have the same type as RecordList, and are empty when ReturnAffectedRecords is False.
ReturnAffectedRecords
Every attribute is compared except the identifier and those in IgnoredAttributesCSV. If any differs, the record is written in full.
IgnoredAttributesCSV
-1
Ignored attributes are still written when another attribute differs. That suits ModifiedAt, which then changes only on real changes. For CreatedAt or CreatedBy, make sure the records carry their stored values, or an update overwrites them.
ModifiedAt
CreatedAt
CreatedBy
CreatedRecords
BeforeUpdateRecords
DeleteWhenNotMatched
Deleting: every row missing from RecordList is deleted, so pass the complete list. A filtered or paged list deletes the rest of the table.
TEMP
CREATE TEMPORARY TABLES
For a table in another database, set DBConnectionName.
DBConnectionName
Indicative times for 300,000 records, measured on a laptop with each database in a container:
Set ReturnAffectedRecords to False when you only need the counts, and raise TimeoutSeconds for large lists: the default of 60 applies to each statement.
TimeoutSeconds
BulkMerge raises an exception starting with BulkMerge: before writing anything. If unhandled, the request's transaction rolls back.
BulkMerge:
Tenant_Id
uniqueidentifier
DeletedCount