Skip to content

Commit 1ca3a35

Browse files
committed
fix: error shallowing
1 parent e91b698 commit 1ca3a35

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -627,13 +627,11 @@ const buildWhereClause = ({ schema, query, index, caseInsensitive }): WhereClaus
627627
const distance = fieldValue.$maxDistance;
628628
const distanceInKM = distance * 6371 * 1000;
629629
patterns.push(
630-
`ST_DistanceSphere($${index}:name::geometry, POINT($${index + 1}, $${
631-
index + 2
630+
`ST_DistanceSphere($${index}:name::geometry, POINT($${index + 1}, $${index + 2
632631
})::geometry) <= $${index + 3}`
633632
);
634633
sorts.push(
635-
`ST_DistanceSphere($${index}:name::geometry, POINT($${index + 1}, $${
636-
index + 2
634+
`ST_DistanceSphere($${index}:name::geometry, POINT($${index + 1}, $${index + 2
637635
})::geometry) ASC`
638636
);
639637
values.push(fieldName, point.longitude, point.latitude, distanceInKM);
@@ -681,8 +679,7 @@ const buildWhereClause = ({ schema, query, index, caseInsensitive }): WhereClaus
681679
}
682680
const distanceInKM = distance * 6371 * 1000;
683681
patterns.push(
684-
`ST_DistanceSphere($${index}:name::geometry, POINT($${index + 1}, $${
685-
index + 2
682+
`ST_DistanceSphere($${index}:name::geometry, POINT($${index + 1}, $${index + 2
686683
})::geometry) <= $${index + 3}`
687684
);
688685
values.push(fieldName, point.longitude, point.latitude, distanceInKM);
@@ -877,7 +874,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
877874

878875
const { client, pgp } = createClient(uri, options);
879876
this._client = client;
880-
this._onchange = () => {};
877+
this._onchange = () => { };
881878
this._pgp = pgp;
882879
this._uuid = uuidv4();
883880
this.canSortOnJoinTables = false;
@@ -1018,7 +1015,13 @@ export class PostgresStorageAdapter implements StorageAdapter {
10181015
}
10191016
} catch (e) {
10201017
const columnDoesNotExistError = e.errors && e.errors[0] && e.errors[0].code === '42703';
1021-
if (columnDoesNotExistError && !this.disableIndexFieldValidation) {
1018+
// Specific case when the column does not exist
1019+
if (columnDoesNotExistError) {
1020+
// If the disableIndexFieldValidation is true, we should ignore the error
1021+
if (!this.disableIndexFieldValidation) {
1022+
throw e;
1023+
}
1024+
} else {
10221025
throw e;
10231026
}
10241027
}
@@ -1638,16 +1641,14 @@ export class PostgresStorageAdapter implements StorageAdapter {
16381641
index += 2;
16391642
} else if (fieldValue.__op === 'Remove') {
16401643
updatePatterns.push(
1641-
`$${index}:name = array_remove(COALESCE($${index}:name, '[]'::jsonb), $${
1642-
index + 1
1644+
`$${index}:name = array_remove(COALESCE($${index}:name, '[]'::jsonb), $${index + 1
16431645
}::jsonb)`
16441646
);
16451647
values.push(fieldName, JSON.stringify(fieldValue.objects));
16461648
index += 2;
16471649
} else if (fieldValue.__op === 'AddUnique') {
16481650
updatePatterns.push(
1649-
`$${index}:name = array_add_unique(COALESCE($${index}:name, '[]'::jsonb), $${
1650-
index + 1
1651+
`$${index}:name = array_add_unique(COALESCE($${index}:name, '[]'::jsonb), $${index + 1
16511652
}::jsonb)`
16521653
);
16531654
values.push(fieldName, JSON.stringify(fieldValue.objects));
@@ -1758,8 +1759,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
17581759
updateObject = `COALESCE($${index}:name, '{}'::jsonb)`;
17591760
}
17601761
updatePatterns.push(
1761-
`$${index}:name = (${updateObject} ${deletePatterns} ${incrementPatterns} || $${
1762-
index + 1 + keysToDelete.length
1762+
`$${index}:name = (${updateObject} ${deletePatterns} ${incrementPatterns} || $${index + 1 + keysToDelete.length
17631763
}::jsonb )`
17641764
);
17651765
values.push(fieldName, ...keysToDelete, JSON.stringify(fieldValue));
@@ -2198,8 +2198,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
21982198
groupByFields.push(`"${source}"`);
21992199
}
22002200
columns.push(
2201-
`EXTRACT(${
2202-
mongoAggregateToPostgres[operation]
2201+
`EXTRACT(${mongoAggregateToPostgres[operation]
22032202
} FROM $${index}:name AT TIME ZONE 'UTC')::integer AS $${index + 1}:name`
22042203
);
22052204
values.push(source, alias);

0 commit comments

Comments
 (0)