chore: postgres query block fields (#3347)
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
"@types/testing-library__jest-dom": "5.14.8",
|
||||
"copyfiles": "2.4.1",
|
||||
"cross-env": "7.0.3",
|
||||
"graphql-request": "6.1.0",
|
||||
"express": "4.18.2",
|
||||
"form-data": "3.0.1",
|
||||
"get-port": "5.1.1",
|
||||
|
||||
@@ -124,6 +124,13 @@ export const getTableColumnFromPath = ({
|
||||
if (locale && field.localized && adapter.payload.config.localization) {
|
||||
newTableName = `${tableName}_locales`;
|
||||
joins[tableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
|
||||
if (locale !== 'all') {
|
||||
constraints.push({
|
||||
columnName: '_locale',
|
||||
table: adapter.tables[newTableName],
|
||||
value: locale,
|
||||
});
|
||||
}
|
||||
}
|
||||
return getTableColumnFromPath({
|
||||
adapter,
|
||||
@@ -144,8 +151,15 @@ export const getTableColumnFromPath = ({
|
||||
if (locale && field.localized && adapter.payload.config.localization) {
|
||||
joins[newTableName] = and(
|
||||
eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),
|
||||
eq(adapter[newTableName]._locale, locale),
|
||||
eq(adapter.tables[newTableName]._locale, locale),
|
||||
);
|
||||
if (locale !== 'all') {
|
||||
constraints.push({
|
||||
columnName: '_locale',
|
||||
table: adapter.tables[newTableName],
|
||||
value: locale,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
joins[newTableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
|
||||
}
|
||||
@@ -163,8 +177,61 @@ export const getTableColumnFromPath = ({
|
||||
}
|
||||
|
||||
case 'blocks': {
|
||||
// TODO: implement blocks
|
||||
throw new Error('not implemented');
|
||||
let blockTableColumn: TableColumn;
|
||||
let newTableName: string;
|
||||
const hasBlockField = field.blocks.some((block) => {
|
||||
newTableName = `${tableName}_${toSnakeCase(block.slug)}`;
|
||||
let result;
|
||||
const blockConstraints = [];
|
||||
const blockSelectFields = {};
|
||||
try {
|
||||
result = getTableColumnFromPath({
|
||||
adapter,
|
||||
collectionPath,
|
||||
constraints: blockConstraints,
|
||||
fields: block.fields,
|
||||
joins,
|
||||
locale,
|
||||
pathSegments: pathSegments.slice(1),
|
||||
selectFields: blockSelectFields,
|
||||
tableName: newTableName,
|
||||
});
|
||||
} catch (error) {
|
||||
// this is fine, not every block will have the field
|
||||
}
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
blockTableColumn = result;
|
||||
constraints = constraints.concat(blockConstraints);
|
||||
selectFields = {...selectFields, ...blockSelectFields};
|
||||
if (field.localized && adapter.payload.config.localization) {
|
||||
joins[newTableName] = and(
|
||||
eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID),
|
||||
eq(adapter.tables[newTableName]._locale, locale),
|
||||
);
|
||||
if (locale) {
|
||||
constraints.push({
|
||||
columnName: '_locale',
|
||||
table: adapter.tables[newTableName],
|
||||
value: locale,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
joins[newTableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
if (hasBlockField) {
|
||||
return {
|
||||
columnName: blockTableColumn.columnName,
|
||||
constraints,
|
||||
field: blockTableColumn.field,
|
||||
rawColumn: blockTableColumn.rawColumn,
|
||||
table: adapter.tables[newTableName],
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'relationship':
|
||||
@@ -234,7 +301,7 @@ export const getTableColumnFromPath = ({
|
||||
// case 'select':
|
||||
// case 'point':
|
||||
if (fieldAffectsData(field)) {
|
||||
if (locale && field.localized && adapter.payload.config.localization) {
|
||||
if (field.localized && adapter.payload.config.localization) {
|
||||
newTableName = `${tableName}_locales`;
|
||||
joins[newTableName] = eq(adapter.tables[tableName].id, adapter.tables[newTableName]._parentID);
|
||||
if (locale !== 'all') {
|
||||
|
||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -12988,8 +12988,8 @@ packages:
|
||||
estree-walker: 0.6.1
|
||||
dev: false
|
||||
|
||||
/rollup@3.29.1:
|
||||
resolution: {integrity: sha512-c+ebvQz0VIH4KhhCpDsI+Bik0eT8ZFEVZEYw0cGMVqIP8zc+gnwl7iXCamTw7vzv2MeuZFZfdx5JJIq+ehzDlg==}
|
||||
/rollup@3.29.2:
|
||||
resolution: {integrity: sha512-CJouHoZ27v6siztc21eEQGo0kIcE5D1gVPA571ez0mMYb25LGYGKnVNXpEj5MGlepmDWGXNjDB5q7uNiPHC11A==}
|
||||
engines: {node: '>=14.18.0', npm: '>=8.0.0'}
|
||||
hasBin: true
|
||||
optionalDependencies:
|
||||
@@ -14524,7 +14524,7 @@ packages:
|
||||
'@types/node': 20.5.7
|
||||
esbuild: 0.18.20
|
||||
postcss: 8.4.27
|
||||
rollup: 3.29.1
|
||||
rollup: 3.29.2
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.3
|
||||
dev: false
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { PayloadRequest } from 'payload/types';
|
||||
import type { PayloadRequest } from 'payload/types';
|
||||
|
||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults';
|
||||
import { LocalizedArrays } from './collections/LocalizedArrays';
|
||||
import { LocalizedBlocks } from './collections/LocalizedBlocks';
|
||||
@@ -248,7 +249,38 @@ const config = buildConfigWithDefaults({
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const text = 'block';
|
||||
const blockDoc = await payload.create({
|
||||
collection: 'localized-blocks',
|
||||
data: {
|
||||
title: 'titled',
|
||||
layout: [{
|
||||
blockType: 'text',
|
||||
text,
|
||||
}],
|
||||
}
|
||||
})
|
||||
|
||||
const nope = await payload.create({
|
||||
collection: 'localized-blocks',
|
||||
data: {
|
||||
title: 'titled',
|
||||
layout: [{
|
||||
blockType: 'text',
|
||||
text: 'should not be found',
|
||||
}],
|
||||
}
|
||||
})
|
||||
|
||||
const query = await payload.find({
|
||||
collection: 'localized-blocks',
|
||||
where: {
|
||||
'layout.text': { equals: text }
|
||||
}
|
||||
})
|
||||
|
||||
console.log({ query });
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user