mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
* test to split up root query into sub queries * moved splitter to driver * moved splitter to data-sql * filtered o2m within conversion * removed splitter * fix * fix * util to get root query * refactoring, preparation for root and sub queries * preparations for making separate sub queries * refactoring * implemented creation of sub query * made store in relational metadata mandatory * fixed export * abstracted the database request * get root query definition * preparation to merge streams * started converting nested many queries in converter Co-authored-by: Nicola Krumschmidt <nickrum@users.noreply.github.com> * refactoring * at least two childnodes for logical operator * refactoring missing module * fixed tests for fields * refactoring, mainly rename current to internal * start integrating second approach * getting closer but wip * getting closer * fixed naming * merged streams into final stream Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> * fixed returning array Co-authored-by: Nicola Krumschmidt <nickrum@users.noreply.github.com> * added generic type * use existing many join node again * fixed test * made use of generic type * changed wording for relational stuff * composite keys * new generator for sub query parameters Co-authored-by: Nicola Krumschmidt <nickrum@users.noreply.github.com> * worked on index test * more specific return type for driver * fixed index file tests * removed approach on abstract query level * worked on index test but wip * simple test for nested many node * continued on index test * finally finished test * randomized test values again * moved common nested many logic up to data-sql * remove closing controller * typedocs and error handling * single test for nested many querying logic * refactor: added utility function for streams * Remove unneeded type declaration * Remove bind call * Use AtLeastOneElement type alias * Use unknown instead of any as value of Records * Rename loadAllResultIntoMemory to readToEnd * Fix o2m with compound keys * Fix type error in createJoin * Simplify AbstractSqlNestedMany type * catch error of conversion in data-sql * removed additional error handling in driver * replaced table alias with actual table name * Allow join field values to be numbers again * Clarify property names on AbstractSqlNestedMany some more * nested many node creation tests * docs --------- Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> Co-authored-by: Nicola Krumschmidt <nickrum@users.noreply.github.com> Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> Co-authored-by: Nicola Krumschmidt <nicola.krumschmidt@freenet.de>
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import type { ReadableStream } from 'node:stream/web';
|
|
import type { AbstractQuery } from './types/abstract-query.js';
|
|
import type { DataDriver } from './types/driver.js';
|
|
|
|
export class DataEngine {
|
|
#stores: Map<string, DataDriver>;
|
|
|
|
constructor() {
|
|
this.#stores = new Map();
|
|
}
|
|
|
|
/** Registers a new data store for use in queries */
|
|
async registerStore(name: string, driver: DataDriver) {
|
|
await driver.register?.();
|
|
this.#stores.set(name, driver);
|
|
}
|
|
|
|
/** Access the driver of a given store. Errors if it hasn't been registered */
|
|
store(name: string): DataDriver {
|
|
const store = this.#stores.get(name);
|
|
|
|
if (!store) {
|
|
throw new Error(`Store "${name}" doesn't exist.`);
|
|
}
|
|
|
|
return store;
|
|
}
|
|
|
|
/** Execute a root abstract query */
|
|
async query(query: AbstractQuery): Promise<ReadableStream<Record<string, unknown>>> {
|
|
return this.store(query.store).query(query);
|
|
}
|
|
|
|
/** Gracefully shutdown connected drivers */
|
|
async destroy() {
|
|
await Promise.all(Array.from(this.#stores.values()).map((driver) => driver.destroy?.()));
|
|
}
|
|
}
|