Skip to content

Commit f81237a

Browse files
committed
Add forceOverwrite to bulkLoad
1 parent fa02be7 commit f81237a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/core/src/database/declarative-database.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,15 +643,17 @@ export class DeclarativeDatabase {
643643
async bulkLoad(
644644
tableName: string,
645645
rows: Record<string, any>[],
646-
onConstraintViolation: ConstraintViolationStrategy = ConstraintViolationStrategy.ThrowException
646+
onConstraintViolation: ConstraintViolationStrategy = ConstraintViolationStrategy.ThrowException,
647+
forceOverwrite: boolean = false
647648
): Promise<void> {
648-
return this.enqueue(() => this._bulkLoad(tableName, rows, onConstraintViolation));
649+
return this.enqueue(() => this._bulkLoad(tableName, rows, onConstraintViolation, forceOverwrite));
649650
}
650651

651652
private async _bulkLoad(
652653
tableName: string,
653654
rows: Record<string, any>[],
654-
onConstraintViolation: ConstraintViolationStrategy = ConstraintViolationStrategy.ThrowException
655+
onConstraintViolation: ConstraintViolationStrategy = ConstraintViolationStrategy.ThrowException,
656+
forceOverwrite: boolean = false
655657
): Promise<void> {
656658
this.ensureInitialized();
657659

@@ -716,7 +718,13 @@ export class DeclarativeDatabase {
716718
const hlcColName = `${colName}__hlc`;
717719
const remoteHlcString = row[hlcColName];
718720

719-
if (remoteHlcString) {
721+
if (forceOverwrite) {
722+
// Force overwrite: always use server data regardless of timestamps
723+
valuesToUpdate[colName] = value;
724+
if (remoteHlcString) {
725+
valuesToUpdate[hlcColName] = remoteHlcString;
726+
}
727+
} else if (remoteHlcString) {
720728
const localHlcValue = (existing as any)[hlcColName];
721729

722730
// Per-column LWW comparison using string comparison

0 commit comments

Comments
 (0)