mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Merge pull request #795 from nickrum/sqlite-update-fix
Pass knex instance to applyFilter
This commit is contained in:
@@ -164,7 +164,7 @@ async function getDBQuery(
|
||||
|
||||
query.sort = query.sort || [{ column: primaryKeyField, order: 'asc' }];
|
||||
|
||||
await applyQuery(table, dbQuery, queryCopy);
|
||||
await applyQuery(knex, table, dbQuery, queryCopy);
|
||||
|
||||
return dbQuery;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ export class MetaService {
|
||||
const dbQuery = database(collection).count('*', { as: 'count' });
|
||||
|
||||
if (query.filter) {
|
||||
await applyFilter(dbQuery, query.filter, collection);
|
||||
await applyFilter(this.knex, dbQuery, query.filter, collection);
|
||||
}
|
||||
|
||||
const records = await dbQuery;
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import { QueryBuilder } from 'knex';
|
||||
import { Query, Filter } from '../types';
|
||||
import database, { schemaInspector } from '../database';
|
||||
import { schemaInspector } from '../database';
|
||||
import Knex from 'knex';
|
||||
import { clone, isPlainObject } from 'lodash';
|
||||
|
||||
export default async function applyQuery(collection: string, dbQuery: QueryBuilder, query: Query) {
|
||||
export default async function applyQuery(
|
||||
knex: Knex,
|
||||
collection: string,
|
||||
dbQuery: QueryBuilder,
|
||||
query: Query
|
||||
) {
|
||||
if (query.filter) {
|
||||
await applyFilter(dbQuery, query.filter, collection);
|
||||
await applyFilter(knex, dbQuery, query.filter, collection);
|
||||
}
|
||||
|
||||
if (query.sort) {
|
||||
@@ -46,8 +52,13 @@ export default async function applyQuery(collection: string, dbQuery: QueryBuild
|
||||
}
|
||||
}
|
||||
|
||||
export async function applyFilter(rootQuery: QueryBuilder, rootFilter: Filter, collection: string) {
|
||||
const relations = await database.select('*').from('directus_relations');
|
||||
export async function applyFilter(
|
||||
knex: Knex,
|
||||
rootQuery: QueryBuilder,
|
||||
rootFilter: Filter,
|
||||
collection: string
|
||||
) {
|
||||
const relations = await knex.select('*').from('directus_relations');
|
||||
|
||||
addWhereClauses(rootQuery, rootFilter, collection);
|
||||
addJoins(rootQuery, rootFilter, collection);
|
||||
|
||||
Reference in New Issue
Block a user