orchid-orm 1.38.1 → 1.38.2

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.
@@ -14,23 +14,30 @@ const compareSqlExpressions = async (tableExpressions, adapter) => {
14
14
  tableExpressions.map(async ({ source, compare, handle }) => {
15
15
  const viewName = `orchidTmpView${id++}`;
16
16
  const values = [];
17
+ let result;
17
18
  try {
18
- const sql = `CREATE TEMPORARY VIEW ${viewName} AS (SELECT ${compare.map(
19
- ({ inDb: inDb2, inCode }, i) => `${inDb2} AS "*inDb-${i}*", ${inCode.map(
20
- (s, j) => `(${typeof s === "string" ? s : s.toSQL({ values })}) "*inCode-${i}-${j}*"`
21
- ).join(", ")}`
22
- ).join(", ")} FROM ${source})`;
23
- await adapter.query({ text: sql, values });
24
- } catch (err) {
19
+ const results = await adapter.query({
20
+ // It is important to run `CREATE TEMPORARY VIEW` and `DROP VIEW` on the same db connection,
21
+ // that's why SQLs are combined into a single query.
22
+ text: [
23
+ `CREATE TEMPORARY VIEW ${viewName} AS (SELECT ${compare.map(
24
+ ({ inDb: inDb2, inCode }, i) => `${inDb2} AS "*inDb-${i}*", ${inCode.map(
25
+ (s, j) => `(${typeof s === "string" ? s : s.toSQL({ values })}) "*inCode-${i}-${j}*"`
26
+ ).join(", ")}`
27
+ ).join(", ")} FROM ${source})`,
28
+ `SELECT pg_get_viewdef('${viewName}') v`,
29
+ `DROP VIEW ${viewName}`
30
+ ].join("; "),
31
+ values
32
+ });
33
+ result = results[1];
34
+ } catch {
35
+ }
36
+ if (!result) {
25
37
  handle();
26
38
  return;
27
39
  }
28
- const {
29
- rows: [{ v }]
30
- } = await adapter.query(
31
- `SELECT pg_get_viewdef('${viewName}') v`
32
- );
33
- await adapter.query(`DROP VIEW ${viewName}`);
40
+ const v = result.rows[0].v;
34
41
  let pos = 7;
35
42
  const rgx = /\s+AS\s+"\*(inDb-\d+|inCode-\d+-\d+)\*",?/g;
36
43
  let match;
@@ -1225,6 +1232,7 @@ const collectCodeComparableItemsType = (config, codeItems, key) => {
1225
1232
  });
1226
1233
  };
1227
1234
  const normalizeItem = (item) => {
1235
+ if (item.using) item.using = item.using.toLowerCase();
1228
1236
  if (item.using === "btree") item.using = void 0;
1229
1237
  if (!item.unique) item.unique = void 0;
1230
1238
  if (item.nullsNotDistinct === false) item.nullsNotDistinct = void 0;