@payloadcms/db-postgres 3.0.0-beta.7 → 3.0.0-canary.2077da8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. package/dist/connect.d.ts.map +1 -1
  2. package/dist/connect.js +12 -7
  3. package/dist/connect.js.map +1 -1
  4. package/dist/count.d.ts +3 -0
  5. package/dist/count.d.ts.map +1 -0
  6. package/dist/count.js +41 -0
  7. package/dist/count.js.map +1 -0
  8. package/dist/create.d.ts.map +1 -1
  9. package/dist/create.js +3 -5
  10. package/dist/create.js.map +1 -1
  11. package/dist/createGlobal.d.ts.map +1 -1
  12. package/dist/createGlobal.js +3 -5
  13. package/dist/createGlobal.js.map +1 -1
  14. package/dist/createGlobalVersion.d.ts +1 -1
  15. package/dist/createGlobalVersion.d.ts.map +1 -1
  16. package/dist/createGlobalVersion.js +2 -6
  17. package/dist/createGlobalVersion.js.map +1 -1
  18. package/dist/createMigration.d.ts.map +1 -1
  19. package/dist/createMigration.js +58 -37
  20. package/dist/createMigration.js.map +1 -1
  21. package/dist/createVersion.d.ts.map +1 -1
  22. package/dist/createVersion.js +10 -18
  23. package/dist/createVersion.js.map +1 -1
  24. package/dist/deleteMany.d.ts.map +1 -1
  25. package/dist/deleteMany.js +2 -5
  26. package/dist/deleteMany.js.map +1 -1
  27. package/dist/deleteOne.d.ts.map +1 -1
  28. package/dist/deleteOne.js +4 -7
  29. package/dist/deleteOne.js.map +1 -1
  30. package/dist/deleteVersions.d.ts.map +1 -1
  31. package/dist/deleteVersions.js +2 -6
  32. package/dist/deleteVersions.js.map +1 -1
  33. package/dist/destroy.d.ts.map +1 -1
  34. package/dist/destroy.js +11 -7
  35. package/dist/destroy.js.map +1 -1
  36. package/dist/exports/migration-utils.d.ts +2 -0
  37. package/dist/exports/migration-utils.d.ts.map +1 -0
  38. package/dist/exports/migration-utils.js +3 -0
  39. package/dist/exports/migration-utils.js.map +1 -0
  40. package/dist/find/buildFindManyArgs.d.ts +5 -1
  41. package/dist/find/buildFindManyArgs.d.ts.map +1 -1
  42. package/dist/find/buildFindManyArgs.js +4 -3
  43. package/dist/find/buildFindManyArgs.js.map +1 -1
  44. package/dist/find/findMany.d.ts.map +1 -1
  45. package/dist/find/findMany.js +5 -16
  46. package/dist/find/findMany.js.map +1 -1
  47. package/dist/find/traverseFields.d.ts +3 -2
  48. package/dist/find/traverseFields.d.ts.map +1 -1
  49. package/dist/find/traverseFields.js +26 -24
  50. package/dist/find/traverseFields.js.map +1 -1
  51. package/dist/find.d.ts.map +1 -1
  52. package/dist/find.js +2 -5
  53. package/dist/find.js.map +1 -1
  54. package/dist/findGlobal.d.ts.map +1 -1
  55. package/dist/findGlobal.js +2 -5
  56. package/dist/findGlobal.js.map +1 -1
  57. package/dist/findGlobalVersions.d.ts.map +1 -1
  58. package/dist/findGlobalVersions.js +2 -6
  59. package/dist/findGlobalVersions.js.map +1 -1
  60. package/dist/findOne.d.ts.map +1 -1
  61. package/dist/findOne.js +2 -5
  62. package/dist/findOne.js.map +1 -1
  63. package/dist/findVersions.d.ts.map +1 -1
  64. package/dist/findVersions.js +2 -6
  65. package/dist/findVersions.js.map +1 -1
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +17 -8
  68. package/dist/index.js.map +1 -1
  69. package/dist/init.d.ts.map +1 -1
  70. package/dist/init.js +19 -22
  71. package/dist/init.js.map +1 -1
  72. package/dist/migrate.js.map +1 -1
  73. package/dist/migrateDown.js.map +1 -1
  74. package/dist/migrateFresh.js.map +1 -1
  75. package/dist/migrateRefresh.js.map +1 -1
  76. package/dist/migrateReset.js.map +1 -1
  77. package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
  78. package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
  79. package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
  80. package/dist/predefinedMigrations/relationships-v2-v3.mjs +11 -0
  81. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +20 -0
  82. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
  83. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +170 -0
  84. package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
  85. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
  86. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
  87. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +191 -0
  88. package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
  89. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
  90. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
  91. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js +56 -0
  92. package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
  93. package/dist/predefinedMigrations/v2-v3/index.d.ts +24 -0
  94. package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
  95. package/dist/predefinedMigrations/v2-v3/index.js +211 -0
  96. package/dist/predefinedMigrations/v2-v3/index.js.map +1 -0
  97. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +19 -0
  98. package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
  99. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +57 -0
  100. package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
  101. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +23 -0
  102. package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
  103. package/dist/predefinedMigrations/v2-v3/traverseFields.js +85 -0
  104. package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
  105. package/dist/predefinedMigrations/v2-v3/types.d.ts +9 -0
  106. package/dist/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
  107. package/dist/predefinedMigrations/v2-v3/types.js +6 -0
  108. package/dist/predefinedMigrations/v2-v3/types.js.map +1 -0
  109. package/dist/queries/buildAndOrConditions.d.ts +3 -4
  110. package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
  111. package/dist/queries/buildAndOrConditions.js +1 -2
  112. package/dist/queries/buildAndOrConditions.js.map +1 -1
  113. package/dist/queries/buildQuery.d.ts +1 -2
  114. package/dist/queries/buildQuery.d.ts.map +1 -1
  115. package/dist/queries/buildQuery.js +1 -5
  116. package/dist/queries/buildQuery.js.map +1 -1
  117. package/dist/queries/getTableColumnFromPath.d.ts +3 -4
  118. package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
  119. package/dist/queries/getTableColumnFromPath.js +248 -143
  120. package/dist/queries/getTableColumnFromPath.js.map +1 -1
  121. package/dist/queries/parseParams.d.ts +3 -4
  122. package/dist/queries/parseParams.d.ts.map +1 -1
  123. package/dist/queries/parseParams.js +7 -6
  124. package/dist/queries/parseParams.js.map +1 -1
  125. package/dist/queries/selectDistinct.d.ts +3 -4
  126. package/dist/queries/selectDistinct.d.ts.map +1 -1
  127. package/dist/queries/selectDistinct.js +3 -14
  128. package/dist/queries/selectDistinct.js.map +1 -1
  129. package/dist/queryDrafts.d.ts.map +1 -1
  130. package/dist/queryDrafts.js +2 -6
  131. package/dist/queryDrafts.js.map +1 -1
  132. package/dist/schema/build.d.ts +11 -6
  133. package/dist/schema/build.d.ts.map +1 -1
  134. package/dist/schema/build.js +208 -124
  135. package/dist/schema/build.js.map +1 -1
  136. package/dist/schema/{getTableName.d.ts → createTableName.d.ts} +5 -7
  137. package/dist/schema/createTableName.d.ts.map +1 -0
  138. package/dist/schema/createTableName.js +31 -0
  139. package/dist/schema/createTableName.js.map +1 -0
  140. package/dist/schema/traverseFields.d.ts +4 -6
  141. package/dist/schema/traverseFields.d.ts.map +1 -1
  142. package/dist/schema/traverseFields.js +145 -61
  143. package/dist/schema/traverseFields.js.map +1 -1
  144. package/dist/schema/validateExistingBlockIsIdentical.d.ts +2 -1
  145. package/dist/schema/validateExistingBlockIsIdentical.d.ts.map +1 -1
  146. package/dist/schema/validateExistingBlockIsIdentical.js +13 -7
  147. package/dist/schema/validateExistingBlockIsIdentical.js.map +1 -1
  148. package/dist/transactions/beginTransaction.d.ts.map +1 -1
  149. package/dist/transactions/beginTransaction.js +4 -0
  150. package/dist/transactions/beginTransaction.js.map +1 -1
  151. package/dist/transform/read/index.d.ts +3 -1
  152. package/dist/transform/read/index.d.ts.map +1 -1
  153. package/dist/transform/read/index.js +2 -1
  154. package/dist/transform/read/index.js.map +1 -1
  155. package/dist/transform/read/relationship.d.ts.map +1 -1
  156. package/dist/transform/read/relationship.js +0 -4
  157. package/dist/transform/read/relationship.js.map +1 -1
  158. package/dist/transform/read/traverseFields.d.ts +6 -1
  159. package/dist/transform/read/traverseFields.d.ts.map +1 -1
  160. package/dist/transform/read/traverseFields.js +69 -55
  161. package/dist/transform/read/traverseFields.js.map +1 -1
  162. package/dist/transform/write/array.d.ts.map +1 -1
  163. package/dist/transform/write/array.js.map +1 -1
  164. package/dist/transform/write/blocks.js +1 -1
  165. package/dist/transform/write/blocks.js.map +1 -1
  166. package/dist/transform/write/traverseFields.d.ts.map +1 -1
  167. package/dist/transform/write/traverseFields.js +22 -5
  168. package/dist/transform/write/traverseFields.js.map +1 -1
  169. package/dist/types.d.ts +7 -7
  170. package/dist/types.d.ts.map +1 -1
  171. package/dist/types.js.map +1 -1
  172. package/dist/update.d.ts.map +1 -1
  173. package/dist/update.js +3 -7
  174. package/dist/update.js.map +1 -1
  175. package/dist/updateGlobal.d.ts.map +1 -1
  176. package/dist/updateGlobal.js +2 -5
  177. package/dist/updateGlobal.js.map +1 -1
  178. package/dist/updateGlobalVersion.d.ts.map +1 -1
  179. package/dist/updateGlobalVersion.js +2 -6
  180. package/dist/updateGlobalVersion.js.map +1 -1
  181. package/dist/updateVersion.d.ts.map +1 -1
  182. package/dist/updateVersion.js +2 -6
  183. package/dist/updateVersion.js.map +1 -1
  184. package/dist/upsertRow/index.d.ts +1 -1
  185. package/dist/upsertRow/index.d.ts.map +1 -1
  186. package/dist/upsertRow/index.js +9 -6
  187. package/dist/upsertRow/index.js.map +1 -1
  188. package/dist/upsertRow/insertArrays.d.ts.map +1 -1
  189. package/dist/upsertRow/insertArrays.js +3 -3
  190. package/dist/upsertRow/insertArrays.js.map +1 -1
  191. package/dist/upsertRow/types.d.ts +7 -2
  192. package/dist/upsertRow/types.d.ts.map +1 -1
  193. package/dist/upsertRow/types.js.map +1 -1
  194. package/package.json +30 -28
  195. package/dist/schema/getTableName.d.ts.map +0 -1
  196. package/dist/schema/getTableName.js +0 -31
  197. package/dist/schema/getTableName.js.map +0 -1
  198. package/src/index.ts +0 -156
@@ -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,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAI7E,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;IAC7C,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,KAAK,WAAW,GAAG;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,UAAU,EAAE,CAAA;IACzB,KAAK,EAAE,kBAAkB,CAAA;IACzB,uBAAuB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAA;IAClD,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,SAAS,CAAC,EAAE,GAAG,CAAA;IACf,KAAK,EAAE,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;CAC9C,CAAA;AAED,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,CAAC,EAAE,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;IACnD,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAA;IAC1B,MAAM,EAAE,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE,CAAA;IAC9B,WAAW,EAAE,qBAAqB,CAAA;IAClC,KAAK,EAAE,eAAe,CAAA;IACtB,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,2RAiBhC,IAAI,KAAG,WAgcT,CAAA"}
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,MAAM,iBAAiB,CAAA;AAE5D,KAAK,UAAU,GAAG;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;IAC7C,KAAK,EAAE,OAAO,CAAA;CACf,CAAA;AAED,KAAK,WAAW,GAAG;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,UAAU,EAAE,CAAA;IACzB,KAAK,EAAE,kBAAkB,CAAA;IACzB,uBAAuB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAA;IAClD,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,SAAS,CAAC,EAAE,GAAG,CAAA;IACf,KAAK,EAAE,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;CAC9C,CAAA;AAED,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,eAAe,CAAA;IACxB,UAAU,CAAC,EAAE,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;IACnD,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,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"}
@@ -5,12 +5,11 @@ import { fieldAffectsData, tabHasName } from 'payload/types';
5
5
  import { flattenTopLevelFields } from 'payload/utilities';
6
6
  import toSnakeCase from 'to-snake-case';
7
7
  import { v4 as uuid } from 'uuid';
8
- import { getTableName } from '../schema/getTableName.js';
9
8
  /**
10
9
  * Transforms path to table and column name
11
10
  * Adds tables to `join`
12
11
  * @returns TableColumn
13
- */ 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 })=>{
14
13
  const fieldPath = incomingSegments[0];
15
14
  let locale = incomingLocale;
16
15
  const rootTableName = incomingRootTableName || tableName;
@@ -56,7 +55,6 @@ import { getTableName } from '../schema/getTableName.js';
56
55
  ...tab,
57
56
  type: 'tab'
58
57
  })),
59
- joinAliases,
60
58
  joins,
61
59
  locale,
62
60
  pathSegments: pathSegments.slice(1),
@@ -78,7 +76,6 @@ import { getTableName } from '../schema/getTableName.js';
78
76
  constraintPath: `${constraintPath}${field.name}.`,
79
77
  constraints,
80
78
  fields: field.fields,
81
- joinAliases,
82
79
  joins,
83
80
  locale,
84
81
  pathSegments: pathSegments.slice(1),
@@ -97,7 +94,6 @@ import { getTableName } from '../schema/getTableName.js';
97
94
  constraintPath,
98
95
  constraints,
99
96
  fields: field.fields,
100
- joinAliases,
101
97
  joins,
102
98
  locale,
103
99
  pathSegments: pathSegments.slice(1),
@@ -111,14 +107,11 @@ import { getTableName } from '../schema/getTableName.js';
111
107
  case 'group':
112
108
  {
113
109
  if (locale && field.localized && adapter.payload.config.localization) {
114
- newTableName = getTableName({
115
- adapter,
116
- config: field,
117
- locales: true,
118
- parentTableName: tableName,
119
- prefix: `${tableName}_`
110
+ newTableName = `${tableName}${adapter.localesSuffix}`;
111
+ joins.push({
112
+ condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),
113
+ table: adapter.tables[newTableName]
120
114
  });
121
- joins[tableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
122
115
  if (locale !== 'all') {
123
116
  constraints.push({
124
117
  columnName: '_locale',
@@ -135,7 +128,6 @@ import { getTableName } from '../schema/getTableName.js';
135
128
  constraintPath: `${constraintPath}${field.name}.`,
136
129
  constraints,
137
130
  fields: field.fields,
138
- joinAliases,
139
131
  joins,
140
132
  locale,
141
133
  pathSegments: pathSegments.slice(1),
@@ -146,17 +138,88 @@ import { getTableName } from '../schema/getTableName.js';
146
138
  value
147
139
  });
148
140
  }
141
+ case 'select':
142
+ {
143
+ if (field.hasMany) {
144
+ const newTableName = adapter.tableNameMap.get(`${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`);
145
+ if (locale && field.localized && adapter.payload.config.localization) {
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
+ });
150
+ if (locale !== 'all') {
151
+ constraints.push({
152
+ columnName: '_locale',
153
+ table: adapter.tables[newTableName],
154
+ value: locale
155
+ });
156
+ }
157
+ } else {
158
+ joins.push({
159
+ condition: eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),
160
+ table: adapter.tables[newTableName]
161
+ });
162
+ }
163
+ return {
164
+ columnName: 'value',
165
+ constraints,
166
+ field,
167
+ table: adapter.tables[newTableName]
168
+ };
169
+ }
170
+ break;
171
+ }
172
+ case 'text':
173
+ case 'number':
174
+ {
175
+ if (field.hasMany) {
176
+ let tableType = 'texts';
177
+ let columnName = 'text';
178
+ if (field.type === 'number') {
179
+ tableType = 'numbers';
180
+ columnName = 'number';
181
+ }
182
+ newTableName = `${tableName}_${tableType}`;
183
+ const joinConstraints = [
184
+ eq(adapter.tables[tableName].id, adapter.tables[newTableName].parent),
185
+ eq(adapter.tables[newTableName].path, `${constraintPath}${field.name}`)
186
+ ];
187
+ if (locale && field.localized && adapter.payload.config.localization) {
188
+ joins.push({
189
+ condition: and(...joinConstraints, eq(adapter.tables[newTableName]._locale, locale)),
190
+ table: adapter.tables[newTableName]
191
+ });
192
+ if (locale !== 'all') {
193
+ constraints.push({
194
+ columnName: 'locale',
195
+ table: adapter.tables[newTableName],
196
+ value: locale
197
+ });
198
+ }
199
+ } else {
200
+ joins.push({
201
+ condition: and(...joinConstraints),
202
+ table: adapter.tables[newTableName]
203
+ });
204
+ }
205
+ return {
206
+ columnName,
207
+ constraints,
208
+ field,
209
+ table: adapter.tables[newTableName]
210
+ };
211
+ }
212
+ break;
213
+ }
149
214
  case 'array':
150
215
  {
151
- newTableName = getTableName({
152
- adapter,
153
- config: field,
154
- parentTableName: `${tableName}_${tableNameSuffix}`,
155
- prefix: `${tableName}_${tableNameSuffix}`
156
- });
216
+ newTableName = adapter.tableNameMap.get(`${tableName}_${tableNameSuffix}${toSnakeCase(field.name)}`);
157
217
  constraintPath = `${constraintPath}${field.name}.%.`;
158
218
  if (locale && field.localized && adapter.payload.config.localization) {
159
- 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
+ });
160
223
  if (locale !== 'all') {
161
224
  constraints.push({
162
225
  columnName: '_locale',
@@ -165,7 +228,10 @@ import { getTableName } from '../schema/getTableName.js';
165
228
  });
166
229
  }
167
230
  } else {
168
- 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
+ });
169
235
  }
170
236
  return getTableColumnFromPath({
171
237
  adapter,
@@ -173,7 +239,6 @@ import { getTableName } from '../schema/getTableName.js';
173
239
  constraintPath,
174
240
  constraints,
175
241
  fields: field.fields,
176
- joinAliases,
177
242
  joins,
178
243
  locale,
179
244
  pathSegments: pathSegments.slice(1),
@@ -195,16 +260,16 @@ import { getTableName } from '../schema/getTableName.js';
195
260
  ];
196
261
  blockTypes.forEach((blockType)=>{
197
262
  const block = field.blocks.find((block)=>block.slug === blockType);
198
- newTableName = getTableName({
199
- adapter,
200
- config: block,
201
- parentTableName: tableName,
202
- prefix: `${tableName}_blocks_`
263
+ newTableName = adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`);
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
203
269
  });
204
- joins[newTableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
205
270
  constraints.push({
206
271
  columnName: '_path',
207
- table: adapter.tables[newTableName],
272
+ table: newAliasTable,
208
273
  value: pathSegments[0]
209
274
  });
210
275
  });
@@ -216,12 +281,7 @@ import { getTableName } from '../schema/getTableName.js';
216
281
  };
217
282
  }
218
283
  const hasBlockField = field.blocks.some((block)=>{
219
- newTableName = getTableName({
220
- adapter,
221
- config: block,
222
- parentTableName: tableName,
223
- prefix: `${tableName}_blocks_`
224
- });
284
+ newTableName = adapter.tableNameMap.get(`${tableName}_blocks_${toSnakeCase(block.slug)}`);
225
285
  constraintPath = `${constraintPath}${field.name}.%.`;
226
286
  let result;
227
287
  const blockConstraints = [];
@@ -233,7 +293,6 @@ import { getTableName } from '../schema/getTableName.js';
233
293
  constraintPath,
234
294
  constraints: blockConstraints,
235
295
  fields: block.fields,
236
- joinAliases,
237
296
  joins,
238
297
  locale,
239
298
  pathSegments: pathSegments.slice(1),
@@ -255,7 +314,10 @@ import { getTableName } from '../schema/getTableName.js';
255
314
  ...blockSelectFields
256
315
  };
257
316
  if (field.localized && adapter.payload.config.localization) {
258
- 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
+ });
259
321
  if (locale) {
260
322
  constraints.push({
261
323
  columnName: '_locale',
@@ -264,7 +326,10 @@ import { getTableName } from '../schema/getTableName.js';
264
326
  });
265
327
  }
266
328
  } else {
267
- 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
+ });
268
333
  }
269
334
  return true;
270
335
  });
@@ -283,128 +348,168 @@ import { getTableName } from '../schema/getTableName.js';
283
348
  case 'relationship':
284
349
  case 'upload':
285
350
  {
286
- let relationshipFields;
287
- const relationTableName = `${rootTableName}${adapter.relationshipsSuffix}`;
288
351
  const newCollectionPath = pathSegments.slice(1).join('.');
289
- const aliasRelationshipTableName = uuid();
290
- const aliasRelationshipTable = alias(adapter.tables[relationTableName], aliasRelationshipTableName);
291
- // Join in the relationships table
292
- if (locale && field.localized && adapter.payload.config.localization) {
293
- joinAliases.push({
294
- condition: and(eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent), eq(aliasRelationshipTable.locale, locale), like(aliasRelationshipTable.path, `${constraintPath}${field.name}`)),
295
- table: aliasRelationshipTable
296
- });
297
- if (locale !== 'all') {
298
- constraints.push({
299
- columnName: 'locale',
300
- table: aliasRelationshipTable,
301
- 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
302
375
  });
303
376
  }
304
- } else {
305
- // Join in the relationships table
306
- joinAliases.push({
307
- condition: and(eq((aliasTable || adapter.tables[rootTableName]).id, aliasRelationshipTable.parent), like(aliasRelationshipTable.path, `${constraintPath}${field.name}`)),
308
- table: aliasRelationshipTable
309
- });
310
- }
311
- selectFields[`${relationTableName}.path`] = aliasRelationshipTable.path;
312
- let newAliasTable;
313
- if (typeof field.relationTo === 'string') {
314
- const relationshipConfig = adapter.payload.collections[field.relationTo].config;
315
- newTableName = getTableName({
316
- adapter,
317
- config: relationshipConfig
318
- });
319
- // parent to relationship join table
320
- relationshipFields = relationshipConfig.fields;
321
- newAliasTable = alias(adapter.tables[newTableName], toSnakeCase(uuid()));
322
- joinAliases.push({
323
- condition: eq(newAliasTable.id, aliasRelationshipTable[`${field.relationTo}ID`]),
324
- table: newAliasTable
325
- });
326
- 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
+ });
327
402
  return {
328
- columnName: `${field.relationTo}ID`,
329
403
  constraints,
330
404
  field,
405
+ rawColumn: sql.raw(`COALESCE(${tableColumnsNames.join(', ')})`),
331
406
  table: aliasRelationshipTable
332
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');
333
424
  }
334
- } else if (newCollectionPath === 'value') {
335
- const tableColumnsNames = field.relationTo.map((relationTo)=>`"${aliasRelationshipTableName}"."${getTableName({
336
- adapter,
337
- config: adapter.payload.collections[relationTo].config
338
- })}_id"`);
339
- return {
425
+ return getTableColumnFromPath({
426
+ adapter,
427
+ aliasTable: newAliasTable,
428
+ collectionPath: newCollectionPath,
340
429
  constraints,
341
- field,
342
- rawColumn: sql.raw(`COALESCE(${tableColumnsNames.join(', ')})`),
343
- table: aliasRelationshipTable
344
- };
345
- } else if (newCollectionPath === 'relationTo') {
346
- const relationTo = Array.isArray(field.relationTo) ? field.relationTo : [
347
- field.relationTo
348
- ];
349
- 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: '',
350
467
  constraints,
351
- field,
352
- getNotNullColumnByValue: (val)=>{
353
- const matchedRelation = relationTo.find((relation)=>relation === val);
354
- if (matchedRelation) return `${matchedRelation}ID`;
355
- return undefined;
356
- },
357
- table: aliasRelationshipTable
358
- };
359
- } else {
360
- 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
+ });
361
476
  }
362
- return getTableColumnFromPath({
363
- adapter,
364
- aliasTable: newAliasTable,
365
- collectionPath: newCollectionPath,
366
- constraints,
367
- fields: relationshipFields,
368
- joinAliases,
369
- joins,
370
- locale,
371
- pathSegments: pathSegments.slice(1),
372
- rootTableName: newTableName,
373
- selectFields,
374
- tableName: newTableName,
375
- value
376
- });
477
+ break;
377
478
  }
378
479
  default:
379
480
  {
380
- if (fieldAffectsData(field)) {
381
- if (field.localized && adapter.payload.config.localization) {
382
- // If localized, we go to localized table and set aliasTable to undefined
383
- // so it is not picked up below to be used as targetTable
384
- newTableName = `${tableName}${adapter.localesSuffix}`;
385
- const parentTable = aliasTable || adapter.tables[tableName];
386
- joins[newTableName] = eq(parentTable.id, adapter.tables[newTableName]._parentID);
387
- aliasTable = undefined;
388
- if (locale !== 'all') {
389
- constraints.push({
390
- columnName: '_locale',
391
- table: adapter.tables[newTableName],
392
- value: locale
393
- });
394
- }
395
- }
396
- const targetTable = aliasTable || adapter.tables[newTableName];
397
- selectFields[`${newTableName}.${columnPrefix}${field.name}`] = targetTable[`${columnPrefix}${field.name}`];
398
- return {
399
- columnName: `${columnPrefix}${field.name}`,
400
- constraints,
401
- field,
402
- pathSegments,
403
- table: targetTable
404
- };
405
- }
481
+ break;
406
482
  }
407
483
  }
484
+ if (fieldAffectsData(field)) {
485
+ if (field.localized && adapter.payload.config.localization) {
486
+ // If localized, we go to localized table and set aliasTable to undefined
487
+ // so it is not picked up below to be used as targetTable
488
+ const parentTable = aliasTable || adapter.tables[tableName];
489
+ newTableName = `${tableName}${adapter.localesSuffix}`;
490
+ joins.push({
491
+ condition: eq(parentTable.id, adapter.tables[newTableName]._parentID),
492
+ table: adapter.tables[newTableName]
493
+ });
494
+ aliasTable = undefined;
495
+ if (locale !== 'all') {
496
+ constraints.push({
497
+ columnName: '_locale',
498
+ table: adapter.tables[newTableName],
499
+ value: locale
500
+ });
501
+ }
502
+ }
503
+ const targetTable = aliasTable || adapter.tables[newTableName];
504
+ selectFields[`${newTableName}.${columnPrefix}${field.name}`] = targetTable[`${columnPrefix}${field.name}`];
505
+ return {
506
+ columnName: `${columnPrefix}${field.name}`,
507
+ constraints,
508
+ field,
509
+ pathSegments,
510
+ table: targetTable
511
+ };
512
+ }
408
513
  }
409
514
  throw new APIError(`Cannot find field for path at ${fieldPath}`);
410
515
  };