@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.
- package/dist/count.d.ts.map +1 -1
- package/dist/count.js +1 -10
- package/dist/count.js.map +1 -1
- package/dist/createMigration.d.ts.map +1 -1
- package/dist/createMigration.js +58 -37
- package/dist/createMigration.js.map +1 -1
- package/dist/createVersion.d.ts.map +1 -1
- package/dist/createVersion.js +2 -6
- package/dist/createVersion.js.map +1 -1
- package/dist/deleteOne.js +2 -2
- package/dist/deleteOne.js.map +1 -1
- package/dist/exports/migration-utils.d.ts +2 -0
- package/dist/exports/migration-utils.d.ts.map +1 -0
- package/dist/exports/migration-utils.js +3 -0
- package/dist/exports/migration-utils.js.map +1 -0
- package/dist/find/buildFindManyArgs.d.ts +5 -1
- package/dist/find/buildFindManyArgs.d.ts.map +1 -1
- package/dist/find/buildFindManyArgs.js +2 -1
- package/dist/find/buildFindManyArgs.js.map +1 -1
- package/dist/find/findMany.d.ts.map +1 -1
- package/dist/find/findMany.js +4 -15
- package/dist/find/findMany.js.map +1 -1
- package/dist/find/traverseFields.d.ts +3 -2
- package/dist/find/traverseFields.d.ts.map +1 -1
- package/dist/find/traverseFields.js +22 -4
- package/dist/find/traverseFields.js.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +14 -19
- package/dist/init.js.map +1 -1
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts +4 -0
- package/dist/predefinedMigrations/relationships-v2-v3.d.ts.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.js.map +1 -0
- package/dist/predefinedMigrations/relationships-v2-v3.mjs +11 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts +20 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js +170 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/index.js.map +1 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts +11 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js +191 -0
- package/dist/predefinedMigrations/v2-v3/fetchAndResave/traverseFields.js.map +1 -0
- package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts +3 -0
- package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js +56 -0
- package/dist/predefinedMigrations/v2-v3/groupUpSQLStatements.js.map +1 -0
- package/dist/predefinedMigrations/v2-v3/index.d.ts +24 -0
- package/dist/predefinedMigrations/v2-v3/index.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/index.js +211 -0
- package/dist/predefinedMigrations/v2-v3/index.js.map +1 -0
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts +19 -0
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.js +57 -0
- package/dist/predefinedMigrations/v2-v3/migrateRelationships.js.map +1 -0
- package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts +23 -0
- package/dist/predefinedMigrations/v2-v3/traverseFields.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/traverseFields.js +85 -0
- package/dist/predefinedMigrations/v2-v3/traverseFields.js.map +1 -0
- package/dist/predefinedMigrations/v2-v3/types.d.ts +9 -0
- package/dist/predefinedMigrations/v2-v3/types.d.ts.map +1 -0
- package/dist/predefinedMigrations/v2-v3/types.js +6 -0
- package/dist/predefinedMigrations/v2-v3/types.js.map +1 -0
- package/dist/queries/buildAndOrConditions.d.ts +3 -4
- package/dist/queries/buildAndOrConditions.d.ts.map +1 -1
- package/dist/queries/buildAndOrConditions.js +1 -2
- package/dist/queries/buildAndOrConditions.js.map +1 -1
- package/dist/queries/buildQuery.d.ts +1 -2
- package/dist/queries/buildQuery.d.ts.map +1 -1
- package/dist/queries/buildQuery.js +1 -5
- package/dist/queries/buildQuery.js.map +1 -1
- package/dist/queries/getTableColumnFromPath.d.ts +3 -4
- package/dist/queries/getTableColumnFromPath.d.ts.map +1 -1
- package/dist/queries/getTableColumnFromPath.js +168 -96
- package/dist/queries/getTableColumnFromPath.js.map +1 -1
- package/dist/queries/parseParams.d.ts +3 -4
- package/dist/queries/parseParams.d.ts.map +1 -1
- package/dist/queries/parseParams.js +1 -3
- package/dist/queries/parseParams.js.map +1 -1
- package/dist/queries/selectDistinct.d.ts +3 -4
- package/dist/queries/selectDistinct.d.ts.map +1 -1
- package/dist/queries/selectDistinct.js +3 -14
- package/dist/queries/selectDistinct.js.map +1 -1
- package/dist/schema/build.d.ts +8 -4
- package/dist/schema/build.d.ts.map +1 -1
- package/dist/schema/build.js +161 -112
- package/dist/schema/build.js.map +1 -1
- package/dist/schema/traverseFields.d.ts +4 -6
- package/dist/schema/traverseFields.d.ts.map +1 -1
- package/dist/schema/traverseFields.js +103 -40
- package/dist/schema/traverseFields.js.map +1 -1
- package/dist/transform/read/index.d.ts +3 -1
- package/dist/transform/read/index.d.ts.map +1 -1
- package/dist/transform/read/index.js +2 -1
- package/dist/transform/read/index.js.map +1 -1
- package/dist/transform/read/relationship.d.ts.map +1 -1
- package/dist/transform/read/relationship.js +0 -4
- package/dist/transform/read/relationship.js.map +1 -1
- package/dist/transform/read/traverseFields.d.ts +6 -1
- package/dist/transform/read/traverseFields.d.ts.map +1 -1
- package/dist/transform/read/traverseFields.js +69 -55
- package/dist/transform/read/traverseFields.js.map +1 -1
- package/dist/transform/write/traverseFields.d.ts.map +1 -1
- package/dist/transform/write/traverseFields.js +20 -3
- package/dist/transform/write/traverseFields.js.map +1 -1
- package/dist/update.d.ts.map +1 -1
- package/dist/update.js +1 -2
- package/dist/update.js.map +1 -1
- package/dist/upsertRow/index.d.ts +1 -1
- package/dist/upsertRow/index.d.ts.map +1 -1
- package/dist/upsertRow/index.js +3 -1
- package/dist/upsertRow/index.js.map +1 -1
- package/dist/upsertRow/types.d.ts +5 -0
- package/dist/upsertRow/types.d.ts.map +1 -1
- package/dist/upsertRow/types.js.map +1 -1
- 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
|
5
|
-
export declare function buildAndOrConditions({ adapter, fields,
|
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
|
-
|
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,
|
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,
|
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
|
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"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAK/E,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAEjD,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,GAAG,CAAA;IACd,KAAK,EAAE,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;CAC9C,EAAE,CAAA;AAEH,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,
|
1
|
+
{"version":3,"file":"buildQuery.d.ts","sourceRoot":"","sources":["../../src/queries/buildQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAK/E,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAEjD,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,GAAG,CAAA;IACd,KAAK,EAAE,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;CAC9C,EAAE,CAAA;AAEH,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE,eAAe,CAAA;IACxB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,KAAK,EAAE,qBAAqB,CAAA;IAC5B,OAAO,EAAE;QACP,MAAM,EAAE,aAAa,CAAA;QACrB,KAAK,EAAE,OAAO,GAAG,GAAG,OAAO,IAAI,CAAA;KAChC,CAAA;IACD,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC3C,KAAK,EAAE,GAAG,CAAA;CACX,CAAA;AACD,QAAA,MAAM,UAAU,wEAOb,cAAc,KAAG,QAAQ,MAAM,CA2EjC,CAAA;AAED,eAAe,UAAU,CAAA"}
|
@@ -5,8 +5,7 @@ const buildQuery = 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
|
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
|
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
|
-
|
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,
|
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,
|
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"}
|
@@ -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,
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
-
|
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:
|
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
|
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
|
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
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
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
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
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
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
});
|
375
|
-
return {
|
425
|
+
return getTableColumnFromPath({
|
426
|
+
adapter,
|
427
|
+
aliasTable: newAliasTable,
|
428
|
+
collectionPath: newCollectionPath,
|
376
429
|
constraints,
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
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
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
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
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
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
|
-
|
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({
|