mirror of
https://github.com/directus/directus.git
synced 2026-02-18 09:11:56 -05:00
Add support for search query param
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { AST, NestedCollectionAST } from '../types/ast';
|
||||
import { uniq } from 'lodash';
|
||||
import database from './index';
|
||||
import database, { schemaInspector } from './index';
|
||||
import { Query } from '../types/query';
|
||||
|
||||
export default async function runAST(ast: AST, query = ast.query) {
|
||||
@@ -69,6 +69,24 @@ export default async function runAST(ast: AST, query = ast.query) {
|
||||
dbQuery.limit(1).first();
|
||||
}
|
||||
|
||||
if (query.search && ast.type === 'collection') {
|
||||
const columns = await schemaInspector.columnInfo(ast.name);
|
||||
|
||||
columns
|
||||
/** @todo Check if this scales between SQL vendors */
|
||||
.filter(
|
||||
(column) =>
|
||||
column.type.toLowerCase().includes('text') ||
|
||||
column.type.toLowerCase().includes('char')
|
||||
)
|
||||
.forEach((column) => {
|
||||
dbQuery.orWhereRaw(
|
||||
`LOWER(${column.name}) LIKE '%' || LOWER(?) || '%'`,
|
||||
query.search
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
let results = await dbQuery;
|
||||
|
||||
for (const batch of nestedCollections) {
|
||||
|
||||
Reference in New Issue
Block a user