/* eslint-disable @typescript-eslint/method-signature-style */ import type { GraphObject } from 'jsonld'; import type { Frame } from 'jsonld/jsonld-spec'; import type { Entity } from '../../util/Types'; import type { FindAllOptions, FindCountOptions, FindExistsOptions, FindOneOptions, FindOptionsWhere } from '../FindOptionsTypes'; import type { GroupByOptions, GroupByResponse } from '../GroupOptionTypes'; export type RawQueryResult = Record; export interface UpdateOptions { validate?: boolean; } /** * Adapts CRUD operations to a specific persistence layer. */ export interface QueryAdapter { /** * Performs a raw query for data matching the query. */ executeRawQuery(query: string): Promise; /** * Performs a raw query for entities matching the query. The query must be a CONSTRUCT query. */ executeRawConstructQuery(query: string, frame?: Frame): Promise; /** * Performs a raw query for data matching the query. */ executeRawUpdate(query: string): Promise; /** * Finds the first entity by a given find options. * If entity was not found in the database it returns null. */ find(options?: FindOneOptions): Promise; /** * Finds the first entity that matches given where condition. * If entity was not found in the database it returns null. */ findBy(where: FindOptionsWhere): Promise; /** * Finds entities that match given find options. */ findAll(options?: FindAllOptions): Promise; /** * Finds entities that match given where condition. */ findAllBy(where: FindOptionsWhere): Promise; /** * Determines if an entity matching the given where condition exists in the database. */ exists(options?: FindExistsOptions): Promise; /** * Returns a count of entities matching the given where condition in the database. */ count(options?: FindCountOptions): Promise; /** * Saves a given entity in the database. * If entity does not exist in the database then inserts, otherwise updates. */ save(entity: Entity): Promise; /** * Saves all given entities in the database. * If entities do not exist in the database then inserts, otherwise updates. */ save(entities: Entity[]): Promise; /** * Updates an entity partially. */ update(id: string, attributes: Partial): Promise; /** * Updates multiple entities partially. */ update(ids: string[], attributes: Partial): Promise; /** * Removes an entity from the database by id. */ delete(id: string): Promise; /** * Removes multiple entities from the database by id. */ delete(ids: string[]): Promise; /** * Removes a given entity from the database. */ destroy(entity: Entity): Promise; /** * Removes given entities from the database. */ destroy(entities: Entity[]): Promise; /** * Deletes entities by a given criteria. * Unlike destroy method executes a primitive operation without cascades, relations and other operations included. */ // delete(criteria: UpdateOrDeleteCriteria): Promise; /** * Removes all entities from the database. */ destroyAll(): Promise; /** * Groups entities by a given options. */ groupBy(options: GroupByOptions): Promise; }