@saltcorn/data 1.5.5 → 1.5.7

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.
@@ -755,17 +755,23 @@ class Table {
755
755
  const schema = db_1.default.getTenantSchemaPrefix();
756
756
  const pkName = this.pk_name || "id";
757
757
  if (isNode()) {
758
- await db_1.default.query(`delete from ${schema}"${db_1.default.sqlsanitize(this.name)}_sync_info" where ref in (
759
- ${ids.map((row) => row[pkName]).join(",")})`);
758
+ const pkVals = ids.map((row) => row[pkName]);
759
+ await db_1.default.query(`delete from ${schema}"${db_1.default.sqlsanitize(this.name)}_sync_info" where ref = ANY($1)`, [pkVals]);
760
+ const tsParam = timestamp.valueOf() / 1000.0;
761
+ const insertParams = [tsParam];
762
+ const valueClauses = pkVals.map((pkVal, i) => {
763
+ insertParams.push(pkVal);
764
+ return `($${i + 2}, date_trunc('milliseconds', to_timestamp($1)), true)`;
765
+ });
760
766
  await db_1.default.query(`insert into ${schema}"${db_1.default.sqlsanitize(this.name)}_sync_info" (ref, last_modified, deleted)
761
- values ${ids
762
- .map((row) => `(${row[pkName]}, date_trunc('milliseconds', to_timestamp( ${timestamp.valueOf() / 1000.0} ) ), true)`)
763
- .join(",")}`);
767
+ values ${valueClauses.join(",")}`, insertParams);
764
768
  }
765
769
  else {
770
+ const pkVals = ids.map((row) => row[pkName]);
771
+ const placeholders = pkVals.map((_, i) => `$${i + 1}`).join(",");
766
772
  await db_1.default.query(`update "${db_1.default.sqlsanitize(this.name)}_sync_info"
767
773
  set deleted = true, modified_local = true
768
- where ref in (${ids.map((row) => row[pkName]).join(",")})`);
774
+ where ref in (${placeholders})`, pkVals);
769
775
  }
770
776
  }
771
777
  }, (e) => {
@@ -1460,8 +1466,8 @@ class Table {
1460
1466
  }
1461
1467
  else {
1462
1468
  await db_1.default.query(`insert into "${db_1.default.sqlsanitize(this.name)}_sync_info"
1463
- (ref, modified_local, deleted)
1464
- values('${id}', true, false)`);
1469
+ (ref, modified_local, deleted)
1470
+ values($1, true, false)`, [id]);
1465
1471
  }
1466
1472
  }, (e) => {
1467
1473
  require("../db/state")
@@ -1494,8 +1500,8 @@ class Table {
1494
1500
  ]);
1495
1501
  }
1496
1502
  else {
1497
- await db_1.default.query(`update "${db_1.default.sqlsanitize(this.name)}_sync_info" set modified_local = true
1498
- where ref = ${id} and last_modified = ${oldLastModified ? oldLastModified.valueOf() : "null"}`);
1503
+ await db_1.default.query(`update "${db_1.default.sqlsanitize(this.name)}_sync_info" set modified_local = true
1504
+ where ref = $1 and last_modified = $2`, [id, oldLastModified ? oldLastModified.valueOf() : null]);
1499
1505
  }
1500
1506
  }, (e) => {
1501
1507
  require("../db/state")
@@ -1750,15 +1756,15 @@ class Table {
1750
1756
  if (isNode()) {
1751
1757
  // sync_info for insert
1752
1758
  const schemaPrefix = db_1.default.getTenantSchemaPrefix();
1759
+ const tsParam = (syncTimestamp ? syncTimestamp : await db_1.default.time()).valueOf() /
1760
+ 1000.0;
1753
1761
  await db_1.default.query(`insert into ${schemaPrefix}"${db_1.default.sqlsanitize(this.name)}_sync_info"
1754
- (ref, last_modified) values(
1755
- ${id}, date_trunc('milliseconds', to_timestamp(${(syncTimestamp ? syncTimestamp : await db_1.default.time()).valueOf() /
1756
- 1000.0})))`);
1762
+ (ref, last_modified) values($1, date_trunc('milliseconds', to_timestamp($2)))`, [id, tsParam]);
1757
1763
  }
1758
1764
  else {
1759
1765
  await db_1.default.query(`insert into "${db_1.default.sqlsanitize(this.name)}_sync_info"
1760
1766
  (last_modified, ref, modified_local, deleted)
1761
- values(NULL, ${id}, true, false)`);
1767
+ values(NULL, $1, true, false)`, [id]);
1762
1768
  }
1763
1769
  }, (e) => {
1764
1770
  state.log(2, `Error inserting sync info for table ${this.name}: ${e.message}`);