@powersync/web 0.0.0-dev-20260309101613 → 0.0.0-dev-20260311080613
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15528,9 +15528,8 @@ class TriggerManagerImpl {
|
|
|
15528
15528
|
...config
|
|
15529
15529
|
};
|
|
15530
15530
|
}
|
|
15531
|
-
generateTriggerName(operation, destinationTable, triggerId
|
|
15532
|
-
|
|
15533
|
-
return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
15531
|
+
generateTriggerName(operation, destinationTable, triggerId) {
|
|
15532
|
+
return `__ps_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
15534
15533
|
}
|
|
15535
15534
|
/**
|
|
15536
15535
|
* Cleanup any SQLite triggers or tables that are no longer in use.
|
|
@@ -15587,24 +15586,9 @@ class TriggerManagerImpl {
|
|
|
15587
15586
|
}
|
|
15588
15587
|
});
|
|
15589
15588
|
}
|
|
15590
|
-
async createDiffDestinationTable(tableName, options) {
|
|
15591
|
-
const { temporary = true, onlyIfNotExists = false } = options ?? {};
|
|
15592
|
-
const tableTriggerTypeClause = temporary ? 'TEMP' : '';
|
|
15593
|
-
const onlyIfNotExistsClause = onlyIfNotExists ? 'IF NOT EXISTS' : '';
|
|
15594
|
-
await this.db.execute(/* sql */ `
|
|
15595
|
-
CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExistsClause} ${tableName} (
|
|
15596
|
-
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
15597
|
-
id TEXT,
|
|
15598
|
-
operation TEXT,
|
|
15599
|
-
timestamp TEXT,
|
|
15600
|
-
value TEXT,
|
|
15601
|
-
previous_value TEXT
|
|
15602
|
-
)
|
|
15603
|
-
`);
|
|
15604
|
-
}
|
|
15605
15589
|
async createDiffTrigger(options) {
|
|
15606
15590
|
await this.db.waitForReady();
|
|
15607
|
-
const { source, destination, columns, when, hooks,
|
|
15591
|
+
const { source, destination, columns, when, hooks,
|
|
15608
15592
|
// Fall back to the provided default if not given on this level
|
|
15609
15593
|
useStorage = this.defaultConfig.useStorageByDefault } = options;
|
|
15610
15594
|
const operations = Object.keys(when);
|
|
@@ -15631,7 +15615,7 @@ class TriggerManagerImpl {
|
|
|
15631
15615
|
const internalSource = sourceDefinition.internalName;
|
|
15632
15616
|
const triggerIds = [];
|
|
15633
15617
|
const id = await this.getUUID();
|
|
15634
|
-
const releaseStorageClaim = useStorage
|
|
15618
|
+
const releaseStorageClaim = useStorage ? await this.options.claimManager.obtainClaim(id) : null;
|
|
15635
15619
|
/**
|
|
15636
15620
|
* We default to replicating all columns if no columns array is provided.
|
|
15637
15621
|
*/
|
|
@@ -15663,29 +15647,25 @@ class TriggerManagerImpl {
|
|
|
15663
15647
|
disposeWarningListener();
|
|
15664
15648
|
return this.db.writeLock(async (tx) => {
|
|
15665
15649
|
await this.removeTriggers(tx, triggerIds);
|
|
15666
|
-
|
|
15667
|
-
await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
|
|
15668
|
-
}
|
|
15650
|
+
await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
|
|
15669
15651
|
await releaseStorageClaim?.();
|
|
15670
15652
|
});
|
|
15671
15653
|
};
|
|
15672
15654
|
const setup = async (tx) => {
|
|
15673
15655
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
15674
15656
|
await hooks?.beforeCreate?.(tx);
|
|
15675
|
-
|
|
15676
|
-
|
|
15677
|
-
|
|
15678
|
-
|
|
15679
|
-
|
|
15680
|
-
|
|
15681
|
-
|
|
15682
|
-
|
|
15683
|
-
|
|
15684
|
-
|
|
15685
|
-
`);
|
|
15686
|
-
}
|
|
15657
|
+
await tx.execute(/* sql */ `
|
|
15658
|
+
CREATE ${tableTriggerTypeClause} TABLE ${destination} (
|
|
15659
|
+
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
15660
|
+
id TEXT,
|
|
15661
|
+
operation TEXT,
|
|
15662
|
+
timestamp TEXT,
|
|
15663
|
+
value TEXT,
|
|
15664
|
+
previous_value TEXT
|
|
15665
|
+
)
|
|
15666
|
+
`);
|
|
15687
15667
|
if (operations.includes(DiffTriggerOperation.INSERT)) {
|
|
15688
|
-
const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id
|
|
15668
|
+
const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id);
|
|
15689
15669
|
triggerIds.push(insertTriggerId);
|
|
15690
15670
|
await tx.execute(/* sql */ `
|
|
15691
15671
|
CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[DiffTriggerOperation.INSERT]} BEGIN
|
|
@@ -15703,7 +15683,7 @@ class TriggerManagerImpl {
|
|
|
15703
15683
|
`);
|
|
15704
15684
|
}
|
|
15705
15685
|
if (operations.includes(DiffTriggerOperation.UPDATE)) {
|
|
15706
|
-
const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id
|
|
15686
|
+
const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id);
|
|
15707
15687
|
triggerIds.push(updateTriggerId);
|
|
15708
15688
|
await tx.execute(/* sql */ `
|
|
15709
15689
|
CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
|
|
@@ -15723,7 +15703,7 @@ class TriggerManagerImpl {
|
|
|
15723
15703
|
`);
|
|
15724
15704
|
}
|
|
15725
15705
|
if (operations.includes(DiffTriggerOperation.DELETE)) {
|
|
15726
|
-
const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id
|
|
15706
|
+
const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id);
|
|
15727
15707
|
triggerIds.push(deleteTriggerId);
|
|
15728
15708
|
// Create delete trigger for basic JSON
|
|
15729
15709
|
await tx.execute(/* sql */ `
|