@payloadcms/db-postgres 3.0.0-beta.38 → 3.0.0-beta.39

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. package/dist/count.d.ts.map +1 -1
  2. package/dist/count.js +1 -10
  3. package/dist/count.js.map +1 -1
  4. package/dist/createMigration.d.ts.map +1 -1
  5. package/dist/createMigration.js +58 -37
  6. package/dist/createMigration.js.map +1 -1
  7. package/dist/createVersion.d.ts.map +1 -1
  8. package/dist/createVersion.js +2 -6
  9. package/dist/createVersion.js.map +1 -1
  10. package/dist/deleteOne.js +2 -2
  11. package/dist/deleteOne.js.map +1 -1
  12. package/dist/exports/migration-utils.d.ts +2 -0
  13. package/dist/exports/migration-utils.d.ts.map +1 -0
  14. package/dist/exports/migration-utils.js +3 -0
  15. package/dist/exports/migration-utils.js.map +1 -0
  16. package/dist/find/buildFindManyArgs.d.ts +5 -1
  17. package/dist/find/buildFindManyArgs.d.ts.map +1 -1
  18. package/dist/find/buildFindManyArgs.js +2 -1
  19. package/dist/find/buildFindManyArgs.js.map +1 -1
  20. package/dist/find/findMany.d.ts.map +1 -1
  21. package/dist/find/findMany.js +4 -15
  22. package/dist/find/findMany.js.map +1 -1
  23. package/dist/find/traverseFields.d.ts +3 -2
  24. package/dist/find/traverseFields.d.ts.map +1 -1
  25. package/dist/find/traverseFields.js +22 -4
  26. package/dist/find/traverseFields.js.map +1 -1
  27. package/dist/init.d.ts.map +1 -1
  28. package/dist/init.js +14 -19
  29. package/dist/init.js.map +1 -1
  30. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  31. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  32. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  33. package/dist/predefinedMigrations/relationships-v2-v3.mjs +11 -0
  34. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +20 -0
  35. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
  36. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +170 -0
  37. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
  38. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
  39. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
  40. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +191 -0
  41. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
  42. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
  43. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
  44. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js +56 -0
  45. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
  46. package/dist/predefinedMigrations/v2-v3/index.d.ts +24 -0
  47. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
  48. package/dist/predefinedMigrations/v2-v3/index.js +211 -0
  49. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -0
  50. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +19 -0
  51. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
  52. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +57 -0
  53. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
  54. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +23 -0
  55. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
  56. package/dist/predefinedMigrations/v2-v3/traverseFields.js +85 -0
  57. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
  58. package/dist/predefinedMigrations/v2-v3/types.d.ts +9 -0
  59. package/dist/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
  60. package/dist/predefinedMigrations/v2-v3/types.js +6 -0
  61. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -0
  62. package/dist/queries/buildAndOrConditions.d.ts +3 -4
  63. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  64. package/dist/queries/buildAndOrConditions.js +1 -2
  65. package/dist/queries/buildAndOrConditions.js.map +1 -1
  66. package/dist/queries/buildQuery.d.ts +1 -2
  67. package/dist/queries/buildQuery.d.ts.map +1 -1
  68. package/dist/queries/buildQuery.js +1 -5
  69. package/dist/queries/buildQuery.js.map +1 -1
  70. package/dist/queries/getTableColumnFromPath.d.ts +3 -4
  71. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  72. package/dist/queries/getTableColumnFromPath.js +168 -96
  73. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  74. package/dist/queries/parseParams.d.ts +3 -4
  75. package/dist/queries/parseParams.d.ts.map +1 -1
  76. package/dist/queries/parseParams.js +1 -3
  77. package/dist/queries/parseParams.js.map +1 -1
  78. package/dist/queries/selectDistinct.d.ts +3 -4
  79. package/dist/queries/selectDistinct.d.ts.map +1 -1
  80. package/dist/queries/selectDistinct.js +3 -14
  81. package/dist/queries/selectDistinct.js.map +1 -1
  82. package/dist/schema/build.d.ts +8 -4
  83. package/dist/schema/build.d.ts.map +1 -1
  84. package/dist/schema/build.js +161 -112
  85. package/dist/schema/build.js.map +1 -1
  86. package/dist/schema/traverseFields.d.ts +4 -6
  87. package/dist/schema/traverseFields.d.ts.map +1 -1
  88. package/dist/schema/traverseFields.js +103 -40
  89. package/dist/schema/traverseFields.js.map +1 -1
  90. package/dist/transform/read/index.d.ts +3 -1
  91. package/dist/transform/read/index.d.ts.map +1 -1
  92. package/dist/transform/read/index.js +2 -1
  93. package/dist/transform/read/index.js.map +1 -1
  94. package/dist/transform/read/relationship.d.ts.map +1 -1
  95. package/dist/transform/read/relationship.js +0 -4
  96. package/dist/transform/read/relationship.js.map +1 -1
  97. package/dist/transform/read/traverseFields.d.ts +6 -1
  98. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  99. package/dist/transform/read/traverseFields.js +69 -55
  100. package/dist/transform/read/traverseFields.js.map +1 -1
  101. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  102. package/dist/transform/write/traverseFields.js +20 -3
  103. package/dist/transform/write/traverseFields.js.map +1 -1
  104. package/dist/update.d.ts.map +1 -1
  105. package/dist/update.js +1 -2
  106. package/dist/update.js.map +1 -1
  107. package/dist/upsertRow/index.d.ts +1 -1
  108. package/dist/upsertRow/index.d.ts.map +1 -1
  109. package/dist/upsertRow/index.js +3 -1
  110. package/dist/upsertRow/index.js.map +1 -1
  111. package/dist/upsertRow/types.d.ts +5 -0
  112. package/dist/upsertRow/types.d.ts.map +1 -1
  113. package/dist/upsertRow/types.js.map +1 -1
  114. package/package.json +11 -5
@@ -1,14 +1,13 @@
1
1
  import type { SQL } from 'drizzle-orm';
2
2
  import type { Field, Where } from 'payload/types';
3
3
  import type { GenericColumn, PostgresAdapter } from '../types.js';
4
- import type { BuildQueryJoinAliases, BuildQueryJoins } from './buildQuery.js';
5
- export declare function buildAndOrConditions({ adapter, fields, joinAliases, joins, locale, selectFields, tableName, where, }: {
4
+ import type { BuildQueryJoinAliases } from './buildQuery.js';
5
+ export declare function buildAndOrConditions({ adapter, fields, joins, locale, selectFields, tableName, where, }: {
6
6
  adapter: PostgresAdapter;
7
7
  collectionSlug?: string;
8
8
  fields: Field[];
9
9
  globalSlug?: string;
10
- joinAliases: BuildQueryJoinAliases;
11
- joins: BuildQueryJoins;
10
+ joins: BuildQueryJoinAliases;
12
11
  locale?: string;
13
12
  selectFields: Record<string, GenericColumn>;
14
13
  tableName: string;
@@ -1 +1 @@
1
- {"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAI7E,wBAAsB,oBAAoB,CAAC,EACzC,OAAO,EACP,MAAM,EACN,WAAW,EACX,KAAK,EACL,MAAM,EACN,YAAY,EACZ,SAAS,EACT,KAAK,GACN,EAAE;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,qBAAqB,CAAA;IAClC,KAAK,EAAE,eAAe,CAAA;IACtB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAyBjB"}
1
+ {"version":3,"file":"buildAndOrConditions.d.ts","sourceRoot":"","sources":["../../src/queries/buildAndOrConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAI5D,wBAAsB,oBAAoB,CAAC,EACzC,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,YAAY,EACZ,SAAS,EACT,KAAK,GACN,EAAE;IACD,OAAO,EAAE,eAAe,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,qBAAqB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,EAAE,CAAA;CACf,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAwBjB"}
@@ -1,5 +1,5 @@
1
1
  import { parseParams } from './parseParams.js';
2
- export async function buildAndOrConditions({ adapter, fields, joinAliases, joins, locale, selectFields, tableName, where }) {
2
+ export async function buildAndOrConditions({ adapter, fields, joins, locale, selectFields, tableName, where }) {
3
3
  const completedConditions = [];
4
4
  // Loop over all AND / OR operations and add them to the AND / OR query param
5
5
  // Operations should come through as an array
@@ -11,7 +11,6 @@ export async function buildAndOrConditions({ adapter, fields, joinAliases, joins
11
11
  const result = await parseParams({
12
12
  adapter,
13
13
  fields,
14
- joinAliases,
15
14
  joins,
16
15
  locale,
17
16
  selectFields,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { Field, Where } from 'payload/types'\n\nimport type { GenericColumn, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases, BuildQueryJoins } from './buildQuery.js'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n adapter,\n fields,\n joinAliases,\n joins,\n locale,\n selectFields,\n tableName,\n where,\n}: {\n adapter: PostgresAdapter\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n joinAliases: BuildQueryJoinAliases\n joins: BuildQueryJoins\n locale?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: Where[]\n}): Promise<SQL[]> {\n const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n // eslint-disable-next-line no-restricted-syntax\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n // eslint-disable-next-line no-await-in-loop\n const result = await parseParams({\n adapter,\n fields,\n joinAliases,\n joins,\n locale,\n selectFields,\n tableName,\n where: condition,\n })\n if (result && Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","adapter","fields","joinAliases","joins","locale","selectFields","tableName","where","completedConditions","condition","result","Object","keys","length","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAMA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,OAAO,EACPC,MAAM,EACNC,WAAW,EACXC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,SAAS,EACTC,KAAK,EAYN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAC7C,gDAAgD;IAChD,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,4CAA4C;YAC5C,MAAMC,SAAS,MAAMZ,YAAY;gBAC/BE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIC,UAAUC,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAC5CL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
1
+ {"version":3,"sources":["../../src/queries/buildAndOrConditions.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { Field, Where } from 'payload/types'\n\nimport type { GenericColumn, PostgresAdapter } from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\nimport { parseParams } from './parseParams.js'\n\nexport async function buildAndOrConditions({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where,\n}: {\n adapter: PostgresAdapter\n collectionSlug?: string\n fields: Field[]\n globalSlug?: string\n joins: BuildQueryJoinAliases\n locale?: string\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: Where[]\n}): Promise<SQL[]> {\n const completedConditions = []\n // Loop over all AND / OR operations and add them to the AND / OR query param\n // Operations should come through as an array\n // eslint-disable-next-line no-restricted-syntax\n for (const condition of where) {\n // If the operation is properly formatted as an object\n if (typeof condition === 'object') {\n // eslint-disable-next-line no-await-in-loop\n const result = await parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: condition,\n })\n if (result && Object.keys(result).length > 0) {\n completedConditions.push(result)\n }\n }\n }\n return completedConditions\n}\n"],"names":["parseParams","buildAndOrConditions","adapter","fields","joins","locale","selectFields","tableName","where","completedConditions","condition","result","Object","keys","length","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAMA,SAASA,WAAW,QAAQ,mBAAkB;AAE9C,OAAO,eAAeC,qBAAqB,EACzCC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,YAAY,EACZC,SAAS,EACTC,KAAK,EAWN;IACC,MAAMC,sBAAsB,EAAE;IAC9B,6EAA6E;IAC7E,6CAA6C;IAC7C,gDAAgD;IAChD,KAAK,MAAMC,aAAaF,MAAO;QAC7B,sDAAsD;QACtD,IAAI,OAAOE,cAAc,UAAU;YACjC,4CAA4C;YAC5C,MAAMC,SAAS,MAAMX,YAAY;gBAC/BE;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC;gBACAC,OAAOE;YACT;YACA,IAAIC,UAAUC,OAAOC,IAAI,CAACF,QAAQG,MAAM,GAAG,GAAG;gBAC5CL,oBAAoBM,IAAI,CAACJ;YAC3B;QACF;IACF;IACA,OAAOF;AACT"}
@@ -17,8 +17,7 @@ type BuildQueryArgs = {
17
17
  where: Where;
18
18
  };
19
19
  type Result = {
20
- joinAliases: BuildQueryJoinAliases;
21
- joins: BuildQueryJoins;
20
+ joins: BuildQueryJoinAliases;
22
21
  orderBy: {
23
22
  column: GenericColumn;
24
23
  order: typeof asc | typeof desc;
@@ -1 +1 @@
1
- {"version":3,"file":"build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= async function buildQuery({ adapter, fields, locale, sort, ta
5
5
  const selectFields = {
6
6
  id: adapter.tables[tableName].id
7
7
  };
8
- const joins = {};
9
- const joinAliases = [];
8
+ const joins = [];
10
9
  const orderBy = {
11
10
  column: null,
12
11
  order: null
@@ -25,7 +24,6 @@ const buildQuery = async function buildQuery({ adapter, fields, locale, sort, ta
25
24
  adapter,
26
25
  collectionPath: sortPath,
27
26
  fields,
28
- joinAliases,
29
27
  joins,
30
28
  locale,
31
29
  pathSegments: sortPath.replace(/__/g, '.').split('.'),
@@ -55,7 +53,6 @@ const buildQuery = async function buildQuery({ adapter, fields, locale, sort, ta
55
53
  where = await parseParams({
56
54
  adapter,
57
55
  fields,
58
- joinAliases,
59
56
  joins,
60
57
  locale,
61
58
  selectFields,
@@ -64,7 +61,6 @@ const buildQuery = async function buildQuery({ adapter, fields, locale, sort, ta
64
61
  });
65
62
  }
66
63
  return {
67
- joinAliases,
68
64
  joins,
69
65
  orderBy,
70
66
  selectFields,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, Where } from 'payload/types'\n\nimport { asc, desc } from 'drizzle-orm'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\n\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { parseParams } from './parseParams.js'\n\nexport type BuildQueryJoins = Record<string, SQL>\n\nexport type BuildQueryJoinAliases = {\n condition: SQL\n table: GenericTable | PgTableWithColumns<any>\n}[]\n\ntype BuildQueryArgs = {\n adapter: PostgresAdapter\n fields: Field[]\n locale?: string\n sort?: string\n tableName: string\n where: Where\n}\n\ntype Result = {\n joinAliases: BuildQueryJoinAliases\n joins: BuildQueryJoins\n orderBy: {\n column: GenericColumn\n order: typeof asc | typeof desc\n }\n selectFields: Record<string, GenericColumn>\n where: SQL\n}\nconst buildQuery = async function buildQuery({\n adapter,\n fields,\n locale,\n sort,\n tableName,\n where: incomingWhere,\n}: BuildQueryArgs): Promise<Result> {\n const selectFields: Record<string, GenericColumn> = {\n id: adapter.tables[tableName].id,\n }\n const joins: BuildQueryJoins = {}\n const joinAliases: BuildQueryJoinAliases = []\n\n const orderBy: Result['orderBy'] = {\n column: null,\n order: null,\n }\n\n if (sort) {\n let sortPath\n\n if (sort[0] === '-') {\n sortPath = sort.substring(1)\n orderBy.order = desc\n } else {\n sortPath = sort\n orderBy.order = asc\n }\n\n try {\n const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({\n adapter,\n collectionPath: sortPath,\n fields,\n joinAliases,\n joins,\n locale,\n pathSegments: sortPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: sortPath,\n })\n orderBy.column = sortTable?.[sortTableColumnName]\n } catch (err) {\n // continue\n }\n }\n\n if (!orderBy?.column) {\n orderBy.order = desc\n const createdAt = adapter.tables[tableName]?.createdAt\n\n if (createdAt) {\n orderBy.column = createdAt\n } else {\n orderBy.column = adapter.tables[tableName].id\n }\n }\n\n if (orderBy.column) {\n selectFields.sort = orderBy.column\n }\n\n let where: SQL\n\n if (incomingWhere && Object.keys(incomingWhere).length > 0) {\n where = await parseParams({\n adapter,\n fields,\n joinAliases,\n joins,\n locale,\n selectFields,\n tableName,\n where: incomingWhere,\n })\n }\n\n return {\n joinAliases,\n joins,\n orderBy,\n selectFields,\n where,\n }\n}\n\nexport default buildQuery\n"],"names":["asc","desc","getTableColumnFromPath","parseParams","buildQuery","adapter","fields","locale","sort","tableName","where","incomingWhere","selectFields","id","tables","joins","joinAliases","orderBy","column","order","sortPath","substring","columnName","sortTableColumnName","table","sortTable","collectionPath","pathSegments","replace","split","value","err","createdAt","Object","keys","length"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,GAAG,EAAEC,IAAI,QAA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AAGS,QAAQC,MAAM;IACpC;IAEA,IAAIR;IAEJ,IAAIC,iBAAiBsB,OAAOC,IAAI,CAACvB,eAAewB,MAAM,GAAG,GAAG;QAC1DzB,QAAQ,MAAMP,YAAY;YACxBE;YACAC;YACAU;YACAD;YACAR;YACAK;YACAH;YACAC,OAAOC;QACT;IACF;IAEA,OAAO;QACLK;QACAD;QACAE;QACAL;QACAF;IACF;AACF;AAEA,eAAeN,WAAU"}
1
+ {"version":3,"sources":["../../src/queries/buildQuery.ts"],"sourcesContent":["import type { SQL } from 'drizzle-orm'\nimport type { PgTableWithColumns } from 'drizzle-orm/pg-core'\nimport type { Field, Where } from 'payload/types'\n\nimport { asc, desc } from 'drizzle-orm'\n\nimport type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js'\n\nimport { getTableColumnFromPath } from './getTableColumnFromPath.js'\nimport { parseParams } from './parseParams.js'\n\nexport type BuildQueryJoins = Record<string, SQL>\n\nexport type BuildQueryJoinAliases = {\n condition: SQL\n table: GenericTable | PgTableWithColumns<any>\n}[]\n\ntype BuildQueryArgs = {\n adapter: PostgresAdapter\n fields: Field[]\n locale?: string\n sort?: string\n tableName: string\n where: Where\n}\n\ntype Result = {\n joins: BuildQueryJoinAliases\n orderBy: {\n column: GenericColumn\n order: typeof asc | typeof desc\n }\n selectFields: Record<string, GenericColumn>\n where: SQL\n}\nconst buildQuery = async function buildQuery({\n adapter,\n fields,\n locale,\n sort,\n tableName,\n where: incomingWhere,\n}: BuildQueryArgs): Promise<Result> {\n const selectFields: Record<string, GenericColumn> = {\n id: adapter.tables[tableName].id,\n }\n const joins: BuildQueryJoinAliases = []\n\n const orderBy: Result['orderBy'] = {\n column: null,\n order: null,\n }\n\n if (sort) {\n let sortPath\n\n if (sort[0] === '-') {\n sortPath = sort.substring(1)\n orderBy.order = desc\n } else {\n sortPath = sort\n orderBy.order = asc\n }\n\n try {\n const { columnName: sortTableColumnName, table: sortTable } = getTableColumnFromPath({\n adapter,\n collectionPath: sortPath,\n fields,\n joins,\n locale,\n pathSegments: sortPath.replace(/__/g, '.').split('.'),\n selectFields,\n tableName,\n value: sortPath,\n })\n orderBy.column = sortTable?.[sortTableColumnName]\n } catch (err) {\n // continue\n }\n }\n\n if (!orderBy?.column) {\n orderBy.order = desc\n const createdAt = adapter.tables[tableName]?.createdAt\n\n if (createdAt) {\n orderBy.column = createdAt\n } else {\n orderBy.column = adapter.tables[tableName].id\n }\n }\n\n if (orderBy.column) {\n selectFields.sort = orderBy.column\n }\n\n let where: SQL\n\n if (incomingWhere && Object.keys(incomingWhere).length > 0) {\n where = await parseParams({\n adapter,\n fields,\n joins,\n locale,\n selectFields,\n tableName,\n where: incomingWhere,\n })\n }\n\n return {\n joins,\n orderBy,\n selectFields,\n where,\n }\n}\n\nexport default buildQuery\n"],"names":["asc","desc","getTableColumnFromPath","parseParams","buildQuery","adapter","fields","locale","sort","tableName","where","incomingWhere","selectFields","id","tables","joins","orderBy","column","order","sortPath","substring","columnName","sortTableColumnName","table","sortTable","collectionPath","pathSegments","replace","split","value","err","createdAt","Object","keys","length"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,GAAG,EAAEC,IAAI,QAAQ,cAAa;AAIvC,SAASC,sBAAsB,QAAQ,8BAA6B;AACpE,SAASC,WAAW,QAAQ,mBAAkB;AA2B9C,MAAMC,aAAa,eAAeA,WAAW,EAC3CC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,OAAOC,aAAa,EACL;IACf,MAAMC,eAA8C;QAClDC,IAAIR,QAAQS,MAAM,CAACL,UAAU,CAACI,EAAE;IAClC;IACA,MAAME,QAA+B,EAAE;IAEvC,MAAMC,UAA6B;QACjCC,QAAQ;QACRC,OAAO;IACT;IAEA,IAAIV,MAAM;QACR,IAAIW;QAEJ,IAAIX,IAAI,CAAC,EAAE,KAAK,KAAK;YACnBW,WAAWX,KAAKY,SAAS,CAAC;YAC1BJ,QAAQE,KAAK,GAAGjB;QAClB,OAAO;YACLkB,WAAWX;YACXQ,QAAQE,KAAK,GAAGlB;QAClB;QAEA,IAAI;YACF,MAAM,EAAEqB,YAAYC,mBAAmB,EAAEC,OAAOC,SAAS,EAAE,GAAGtB,uBAAuB;gBACnFG;gBACAoB,gBAAgBN;gBAChBb;gBACAS;gBACAR;gBACAmB,cAAcP,SAASQ,OAAO,CAAC,OAAO,KAAKC,KAAK,CAAC;gBACjDhB;gBACAH;gBACAoB,OAAOV;YACT;YACAH,QAAQC,MAAM,GAAGO,WAAW,CAACF,oBAAoB;QACnD,EAAE,OAAOQ,KAAK;QACZ,WAAW;QACb;IACF;IAEA,IAAI,CAACd,SAASC,QAAQ;QACpBD,QAAQE,KAAK,GAAGjB;QAChB,MAAM8B,YAAY1B,QAAQS,MAAM,CAACL,UAAU,EAAEsB;QAE7C,IAAIA,WAAW;YACbf,QAAQC,MAAM,GAAGc;QACnB,OAAO;YACLf,QAAQC,MAAM,GAAGZ,QAAQS,MAAM,CAACL,UAAU,CAACI,EAAE;QAC/C;IACF;IAEA,IAAIG,QAAQC,MAAM,EAAE;QAClBL,aAAaJ,IAAI,GAAGQ,QAAQC,MAAM;IACpC;IAEA,IAAIP;IAEJ,IAAIC,iBAAiBqB,OAAOC,IAAI,CAACtB,eAAeuB,MAAM,GAAG,GAAG;QAC1DxB,QAAQ,MAAMP,YAAY;YACxBE;YACAC;YACAS;YACAR;YACAK;YACAH;YACAC,OAAOC;QACT;IACF;IAEA,OAAO;QACLI;QACAC;QACAJ;QACAF;IACF;AACF;AAEA,eAAeN,WAAU"}
@@ -2,7 +2,7 @@ import type { SQL } from 'drizzle-orm';
2
2
  import type { PgTableWithColumns } from 'drizzle-orm/pg-core';
3
3
  import type { Field, FieldAffectingData, TabAsField } from 'payload/types';
4
4
  import type { GenericColumn, GenericTable, PostgresAdapter } from '../types.js';
5
- import type { BuildQueryJoinAliases, BuildQueryJoins } from './buildQuery.js';
5
+ import type { BuildQueryJoinAliases } from './buildQuery.js';
6
6
  type Constraint = {
7
7
  columnName: string;
8
8
  table: GenericTable | PgTableWithColumns<any>;
@@ -25,8 +25,7 @@ type Args = {
25
25
  constraintPath?: string;
26
26
  constraints?: Constraint[];
27
27
  fields: (Field | TabAsField)[];
28
- joinAliases: BuildQueryJoinAliases;
29
- joins: BuildQueryJoins;
28
+ joins: BuildQueryJoinAliases;
30
29
  locale?: string;
31
30
  pathSegments: string[];
32
31
  rootTableName?: string;
@@ -46,6 +45,6 @@ type Args = {
46
45
  * Adds tables to `join`
47
46
  * @returns TableColumn
48
47
  */
49
- export declare const getTableColumnFromPath: ({ adapter, aliasTable, collectionPath, columnPrefix, constraintPath: incomingConstraintPath, constraints, fields, joinAliases, joins, locale: incomingLocale, pathSegments: incomingSegments, rootTableName: incomingRootTableName, selectFields, tableName, tableNameSuffix, value, }: Args) => TableColumn;
48
+ export declare const getTableColumnFromPath: ({ adapter, aliasTable, collectionPath, columnPrefix, constraintPath: incomingConstraintPath, constraints, fields, joins, locale: incomingLocale, pathSegments: incomingSegments, rootTableName: incomingRootTableName, selectFields, tableName, tableNameSuffix, value, }: Args) => TableColumn;
50
49
  export {};
51
50
  //# sourceMappingURL=getTableColumnFromPath.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getTableColumnFromPath.d.ts","sourceRoot":"","sources":["../../src/queries/getTableColumnFromPath.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAe,UAAU,EAAa,MAAM,eAAe,CAAA;AAUlG,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAA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B,WAAW,CAAC,EAAE,UAAU,EAAE,CAAA;IAC1B,MAAM,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,CAAA;IAC9B,KAAK,EAAE,qBAAqB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,EAAE,CAAA;IACtB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;OAEG;IACH,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AACD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,8QAgBhC,IAAI,KAAG,WAykBT,CAAA"}
@@ -9,7 +9,7 @@ import { v4 as uuid } from 'uuid';
9
9
  * Transforms path to table and column name
10
10
  * Adds tables to `join`
11
11
  * @returns TableColumn
12
- */ export const getTableColumnFromPath = ({ adapter, aliasTable, collectionPath, columnPrefix = '', constraintPath: incomingConstraintPath, constraints = [], fields, joinAliases, joins, locale: incomingLocale, pathSegments: incomingSegments, rootTableName: incomingRootTableName, selectFields, tableName, tableNameSuffix = '', value })=>{
12
+ */ export const getTableColumnFromPath = ({ adapter, aliasTable, collectionPath, columnPrefix = '', constraintPath: incomingConstraintPath, constraints = [], fields, joins, locale: incomingLocale, pathSegments: incomingSegments, rootTableName: incomingRootTableName, selectFields, tableName, tableNameSuffix = '', value })=>{
13
13
  const fieldPath = incomingSegments[0];
14
14
  let locale = incomingLocale;
15
15
  const rootTableName = incomingRootTableName || tableName;
@@ -55,7 +55,6 @@ import { v4 as uuid } from 'uuid';
55
55
  ...tab,
56
56
  type: 'tab'
57
57
  })),
58
- joinAliases,
59
58
  joins,
60
59
  locale,
61
60
  pathSegments: pathSegments.slice(1),
@@ -77,7 +76,6 @@ import { v4 as uuid } from 'uuid';
77
76
  constraintPath: `${constraintPath}${field.name}.`,
78
77
  constraints,
79
78
  fields: field.fields,
80
- joinAliases,
81
79
  joins,
82
80
  locale,
83
81
  pathSegments: pathSegments.slice(1),
@@ -96,7 +94,6 @@ import { v4 as uuid } from 'uuid';
96
94
  constraintPath,
97
95
  constraints,
98
96
  fields: field.fields,
99
- joinAliases,
100
97
  joins,
101
98
  locale,
102
99
  pathSegments: pathSegments.slice(1),
@@ -111,7 +108,10 @@ import { v4 as uuid } from 'uuid';
111
108
  {
112
109
  if (locale && field.localized && adapter.payload.config.localization) {
113
110
  newTableName = `${tableName}${adapter.localesSuffix}`;
114
- joins[tableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
111
+ joins.push({
112
+ condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),
113
+ table: adapter.tables[newTableName]
114
+ });
115
115
  if (locale !== 'all') {
116
116
  constraints.push({
117
117
  columnName: '_locale',
@@ -128,7 +128,6 @@ import { v4 as uuid } from 'uuid';
128
128
  constraintPath: `${constraintPath}${field.name}.`,
129
129
  constraints,
130
130
  fields: field.fields,
131
- joinAliases,
132
131
  joins,
133
132
  locale,
134
133
  pathSegments: pathSegments.slice(1),
@@ -144,7 +143,10 @@ import { v4 as uuid } from 'uuid';
144
143
  if (field.hasMany) {
145
144
  const newTableName = adapter.tableNameMap.get(`${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`);
146
145
  if (locale && field.localized && adapter.payload.config.localization) {
147
- joins[newTableName] = and(eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent), eq(adapter.tables[newTableName]._locale, locale));
146
+ joins.push({
147
+ condition: and(eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent), eq(adapter.tables[newTableName]._locale, locale)),
148
+ table: adapter.tables[newTableName]
149
+ });
148
150
  if (locale !== 'all') {
149
151
  constraints.push({
150
152
  columnName: '_locale',
@@ -153,7 +155,10 @@ import { v4 as uuid } from 'uuid';
153
155
  });
154
156
  }
155
157
  } else {
156
- joins[newTableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent);
158
+ joins.push({
159
+ condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),
160
+ table: adapter.tables[newTableName]
161
+ });
157
162
  }
158
163
  return {
159
164
  columnName: 'value',
@@ -180,7 +185,10 @@ import { v4 as uuid } from 'uuid';
180
185
  eq(adapter.tables[newTableName].path, `${constraintPath}${field.name}`)
181
186
  ];
182
187
  if (locale && field.localized && adapter.payload.config.localization) {
183
- joins[newTableName] = and(...joinConstraints, eq(adapter.tables[newTableName]._locale, locale));
188
+ joins.push({
189
+ condition: and(...joinConstraints, eq(adapter.tables[newTableName]._locale, locale)),
190
+ table: adapter.tables[newTableName]
191
+ });
184
192
  if (locale !== 'all') {
185
193
  constraints.push({
186
194
  columnName: 'locale',
@@ -189,7 +197,10 @@ import { v4 as uuid } from 'uuid';
189
197
  });
190
198
  }
191
199
  } else {
192
- joins[newTableName] = and(...joinConstraints);
200
+ joins.push({
201
+ condition: and(...joinConstraints),
202
+ table: adapter.tables[newTableName]
203
+ });
193
204
  }
194
205
  return {
195
206
  columnName,
@@ -205,7 +216,10 @@ import { v4 as uuid } from 'uuid';
205
216
  newTableName = adapter.tableNameMap.get(`${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`);
206
217
  constraintPath = `${constraintPath}${field.name}.%.`;
207
218
  if (locale && field.localized && adapter.payload.config.localization) {
208
- joins[newTableName] = and(eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID), eq(adapter.tables[newTableName]._locale, locale));
219
+ joins.push({
220
+ condition: and(eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID), eq(adapter.tables[newTableName]._locale, locale)),
221
+ table: adapter.tables[newTableName]
222
+ });
209
223
  if (locale !== 'all') {
210
224
  constraints.push({
211
225
  columnName: '_locale',
@@ -214,7 +228,10 @@ import { v4 as uuid } from 'uuid';
214
228
  });
215
229
  }
216
230
  } else {
217
- joins[newTableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
231
+ joins.push({
232
+ condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),
233
+ table: adapter.tables[newTableName]
234
+ });
218
235
  }
219
236
  return getTableColumnFromPath({
220
237
  adapter,
@@ -222,7 +239,6 @@ import { v4 as uuid } from 'uuid';
222
239
  constraintPath,
223
240
  constraints,
224
241
  fields: field.fields,
225
- joinAliases,
226
242
  joins,
227
243
  locale,
228
244
  pathSegments: pathSegments.slice(1),
@@ -245,10 +261,15 @@ import { v4 as uuid } from 'uuid';
245
261
  blockTypes.forEach((blockType)=>{
246
262
  const block = field.blocks.find((block)=>block.slug === blockType);
247
263
  newTableName = adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`);
248
- joins[newTableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
264
+ const newAliasTableName = toSnakeCase(uuid());
265
+ const newAliasTable = alias(adapter.tables[newTableName], newAliasTableName);
266
+ joins.push({
267
+ condition: eq(adapter.tables[tableName].id, newAliasTable._parentID),
268
+ table: newAliasTable
269
+ });
249
270
  constraints.push({
250
271
  columnName: '_path',
251
- table: adapter.tables[newTableName],
272
+ table: newAliasTable,
252
273
  value: pathSegments[0]
253
274
  });
254
275
  });
@@ -272,7 +293,6 @@ import { v4 as uuid } from 'uuid';
272
293
  constraintPath,
273
294
  constraints: blockConstraints,
274
295
  fields: block.fields,
275
- joinAliases,
276
296
  joins,
277
297
  locale,
278
298
  pathSegments: pathSegments.slice(1),
@@ -294,7 +314,10 @@ import { v4 as uuid } from 'uuid';
294
314
  ...blockSelectFields
295
315
  };
296
316
  if (field.localized && adapter.payload.config.localization) {
297
- joins[newTableName] = and(eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID), eq(adapter.tables[newTableName]._locale, locale));
317
+ joins.push({
318
+ condition: and(eq((aliasTable || adapter.tables[tableName]).id, adapter.tables[newTableName]._parentID), eq(adapter.tables[newTableName]._locale, locale)),
319
+ table: adapter.tables[newTableName]
320
+ });
298
321
  if (locale) {
299
322
  constraints.push({
300
323
  columnName: '_locale',
@@ -303,7 +326,10 @@ import { v4 as uuid } from 'uuid';
303
326
  });
304
327
  }
305
328
  } else {
306
- joins[newTableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
329
+ joins.push({
330
+ condition: eq((aliasTable || adapter.tables[tableName]).id, adapter.tables[newTableName]._parentID),
331
+ table: adapter.tables[newTableName]
332
+ });
307
333
  }
308
334
  return true;
309
335
  });
@@ -322,103 +348,149 @@ import { v4 as uuid } from 'uuid';
322
348
  case 'relationship':
323
349
  case 'upload':
324
350
  {
325
- let relationshipFields;
326
- const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`;
327
351
  const newCollectionPath = pathSegments.slice(1).join('.');
328
- const aliasRelationshipTableName = uuid();
329
- const aliasRelationshipTable = alias(adapter.tables[relationTableName], aliasRelationshipTableName);
330
- // Join in the relationships table
331
- if (locale && field.localized && adapter.payload.config.localization) {
332
- joinAliases.push({
333
- condition: and(eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent), eq(aliasRelationshipTable.locale, locale), like(aliasRelationshipTable.path, `${constraintPath}${field.name}`)),
334
- table: aliasRelationshipTable
335
- });
336
- if (locale !== 'all') {
337
- constraints.push({
338
- columnName: 'locale',
339
- table: aliasRelationshipTable,
340
- value: locale
352
+ if (Array.isArray(field.relationTo) || field.type === 'relationship' && field.hasMany) {
353
+ let relationshipFields;
354
+ const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`;
355
+ const aliasRelationshipTableName = uuid();
356
+ const aliasRelationshipTable = alias(adapter.tables[relationTableName], aliasRelationshipTableName);
357
+ // Join in the relationships table
358
+ if (locale && field.localized && adapter.payload.config.localization) {
359
+ joins.push({
360
+ condition: and(eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent), eq(aliasRelationshipTable.locale, locale), like(aliasRelationshipTable.path, `${constraintPath}${field.name}`)),
361
+ table: aliasRelationshipTable
362
+ });
363
+ if (locale !== 'all') {
364
+ constraints.push({
365
+ columnName: 'locale',
366
+ table: aliasRelationshipTable,
367
+ value: locale
368
+ });
369
+ }
370
+ } else {
371
+ // Join in the relationships table
372
+ joins.push({
373
+ condition: and(eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent), like(aliasRelationshipTable.path, `${constraintPath}${field.name}`)),
374
+ table: aliasRelationshipTable
341
375
  });
342
376
  }
343
- } else {
344
- // Join in the relationships table
345
- joinAliases.push({
346
- condition: and(eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent), like(aliasRelationshipTable.path, `${constraintPath}${field.name}`)),
347
- table: aliasRelationshipTable
348
- });
349
- }
350
- selectFields[`${relationTableName}.path`] = aliasRelationshipTable.path;
351
- let newAliasTable;
352
- if (typeof field.relationTo === 'string') {
353
- const relationshipConfig = adapter.payload.collections[field.relationTo].config;
354
- newTableName = adapter.tableNameMap.get(toSnakeCase(relationshipConfig.slug));
355
- // parent to relationship join table
356
- relationshipFields = relationshipConfig.fields;
357
- newAliasTable = alias(adapter.tables[newTableName], toSnakeCase(uuid()));
358
- joinAliases.push({
359
- condition: eq(newAliasTable.id, aliasRelationshipTable[`${field.relationTo}ID`]),
360
- table: newAliasTable
361
- });
362
- if (newCollectionPath === '' || newCollectionPath === 'id') {
377
+ selectFields[`${relationTableName}.path`] = aliasRelationshipTable.path;
378
+ let newAliasTable;
379
+ if (typeof field.relationTo === 'string') {
380
+ const relationshipConfig = adapter.payload.collections[field.relationTo].config;
381
+ newTableName = adapter.tableNameMap.get(toSnakeCase(relationshipConfig.slug));
382
+ // parent to relationship join table
383
+ relationshipFields = relationshipConfig.fields;
384
+ newAliasTable = alias(adapter.tables[newTableName], toSnakeCase(uuid()));
385
+ joins.push({
386
+ condition: eq(newAliasTable.id, aliasRelationshipTable[`${field.relationTo}ID`]),
387
+ table: newAliasTable
388
+ });
389
+ if (newCollectionPath === '' || newCollectionPath === 'id') {
390
+ return {
391
+ columnName: `${field.relationTo}ID`,
392
+ constraints,
393
+ field,
394
+ table: aliasRelationshipTable
395
+ };
396
+ }
397
+ } else if (newCollectionPath === 'value') {
398
+ const tableColumnsNames = field.relationTo.map((relationTo)=>{
399
+ const relationTableName = adapter.tableNameMap.get(toSnakeCase(adapter.payload.collections[relationTo].config.slug));
400
+ return `"${aliasRelationshipTableName}"."${relationTableName}_id"`;
401
+ });
363
402
  return {
364
- columnName: `${field.relationTo}ID`,
365
403
  constraints,
366
404
  field,
405
+ rawColumn: sql.raw(`COALESCE(${tableColumnsNames.join(', ')})`),
367
406
  table: aliasRelationshipTable
368
407
  };
408
+ } else if (newCollectionPath === 'relationTo') {
409
+ const relationTo = Array.isArray(field.relationTo) ? field.relationTo : [
410
+ field.relationTo
411
+ ];
412
+ return {
413
+ constraints,
414
+ field,
415
+ getNotNullColumnByValue: (val)=>{
416
+ const matchedRelation = relationTo.find((relation)=>relation === val);
417
+ if (matchedRelation) return `${matchedRelation}ID`;
418
+ return undefined;
419
+ },
420
+ table: aliasRelationshipTable
421
+ };
422
+ } else {
423
+ throw new APIError('Not supported');
369
424
  }
370
- } else if (newCollectionPath === 'value') {
371
- const tableColumnsNames = field.relationTo.map((relationTo)=>{
372
- const relationTableName = adapter.tableNameMap.get(toSnakeCase(adapter.payload.collections[relationTo].config.slug));
373
- return `"${aliasRelationshipTableName}"."${relationTableName}_id"`;
374
- });
375
- return {
425
+ return getTableColumnFromPath({
426
+ adapter,
427
+ aliasTable: newAliasTable,
428
+ collectionPath: newCollectionPath,
376
429
  constraints,
377
- field,
378
- rawColumn: sql.raw(`COALESCE(${tableColumnsNames.join(', ')})`),
379
- table: aliasRelationshipTable
380
- };
381
- } else if (newCollectionPath === 'relationTo') {
382
- const relationTo = Array.isArray(field.relationTo) ? field.relationTo : [
383
- field.relationTo
384
- ];
385
- return {
430
+ fields: relationshipFields,
431
+ joins,
432
+ locale,
433
+ pathSegments: pathSegments.slice(1),
434
+ rootTableName: newTableName,
435
+ selectFields,
436
+ tableName: newTableName,
437
+ value
438
+ });
439
+ } else if (pathSegments.length > 1 && !(pathSegments.length === 2 && pathSegments[1] === 'id')) {
440
+ // simple relationships
441
+ const columnName = `${columnPrefix}${field.name}`;
442
+ const newTableName = adapter.tableNameMap.get(toSnakeCase(adapter.payload.collections[field.relationTo].config.slug));
443
+ const aliasTableName = uuid();
444
+ const newAliasTable = alias(adapter.tables[newTableName], aliasTableName);
445
+ if (field.localized && adapter.payload.config.localization) {
446
+ const aliasLocaleTableName = uuid();
447
+ const aliasLocaleTable = alias(adapter.tables[`${rootTableName}${adapter.localesSuffix}`], aliasLocaleTableName);
448
+ joins.push({
449
+ condition: and(eq(aliasLocaleTable._parentID, adapter.tables[rootTableName].id), eq(aliasLocaleTable._locale, locale)),
450
+ table: aliasLocaleTable
451
+ });
452
+ joins.push({
453
+ condition: eq(aliasLocaleTable[columnName], newAliasTable.id),
454
+ table: newAliasTable
455
+ });
456
+ } else {
457
+ joins.push({
458
+ condition: eq(newAliasTable.id, aliasTable ? aliasTable[columnName] : adapter.tables[tableName][columnName]),
459
+ table: newAliasTable
460
+ });
461
+ }
462
+ return getTableColumnFromPath({
463
+ adapter,
464
+ aliasTable: newAliasTable,
465
+ collectionPath: newCollectionPath,
466
+ constraintPath: '',
386
467
  constraints,
387
- field,
388
- getNotNullColumnByValue: (val)=>{
389
- const matchedRelation = relationTo.find((relation)=>relation === val);
390
- if (matchedRelation) return `${matchedRelation}ID`;
391
- return undefined;
392
- },
393
- table: aliasRelationshipTable
394
- };
395
- } else {
396
- throw new APIError('Not supported');
468
+ fields: adapter.payload.collections[field.relationTo].config.fields,
469
+ joins,
470
+ locale,
471
+ pathSegments: pathSegments.slice(1),
472
+ selectFields,
473
+ tableName: newTableName,
474
+ value
475
+ });
397
476
  }
398
- return getTableColumnFromPath({
399
- adapter,
400
- aliasTable: newAliasTable,
401
- collectionPath: newCollectionPath,
402
- constraints,
403
- fields: relationshipFields,
404
- joinAliases,
405
- joins,
406
- locale,
407
- pathSegments: pathSegments.slice(1),
408
- rootTableName: newTableName,
409
- selectFields,
410
- tableName: newTableName,
411
- value
412
- });
477
+ break;
478
+ }
479
+ default:
480
+ {
481
+ break;
413
482
  }
414
483
  }
415
484
  if (fieldAffectsData(field)) {
416
485
  if (field.localized && adapter.payload.config.localization) {
417
486
  // If localized, we go to localized table and set aliasTable to undefined
418
487
  // so it is not picked up below to be used as targetTable
419
- newTableName = `${tableName}${adapter.localesSuffix}`;
420
488
  const parentTable = aliasTable || adapter.tables[tableName];
421
- joins[newTableName] = eq(parentTable.id, adapter.tables[newTableName]._parentID);
489
+ newTableName = `${tableName}${adapter.localesSuffix}`;
490
+ joins.push({
491
+ condition: eq(parentTable.id, adapter.tables[newTableName]._parentID),
492
+ table: adapter.tables[newTableName]
493
+ });
422
494
  aliasTable = undefined;
423
495
  if (locale !== 'all') {
424
496
  constraints.push({