mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Pass knex instance to applyFilter
This fixes a regression introduced in #786. When using a SQLite database, items could not be updated any more. This is due to knex by default only allowing a single connection for SQLite databases and the item update operation using applyFilter inside a transaction which tries to use a different knex instance to connect to the database.
This commit is contained in:
@@ -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