Throw error if table doens't have primary key

Fixes #3130
This commit is contained in:
rijkvanzanten
2020-11-23 10:49:42 -05:00
parent 5a7e11e600
commit c8f9831eb1

View File

@@ -6,6 +6,7 @@ import { PayloadService } from '../services/payload';
import applyQuery from '../utils/apply-query';
import Knex, { QueryBuilder } from 'knex';
import { toArray } from '../utils/to-array';
import { ServiceUnavailableException } from '../../dist/exceptions';
type RunASTOptions = {
query?: AST['query'];
@@ -22,6 +23,17 @@ export default async function runAST(
const knex = options?.knex || database;
for (const [collection, info] of Object.entries(schema)) {
if (!info.primary) {
throw new ServiceUnavailableException(
`Collection "${collection}" doesn't have a primary key column`,
{
service: 'database',
}
);
}
}
if (ast.type === 'm2a') {
const results: { [collection: string]: null | Item | Item[] } = {};