/*! * Copyright (C) 2018-2019 Silas B. Domingos * This source code is licensed under the MIT License as described in the file LICENSE. */ import * as Types from './types'; import * as Filters from './filters'; /** * Data mapper driver interface. */ export interface Driver { /** * Insert the specified entity list into the storage. * @param model Model type. * @param entities Entity list. * @param options Insert options. * @returns Returns a promise to get the Id list of all inserted entities or undefined when an error occurs. */ insert(model: Types.ModelClass, entities: E[], options: O): Promise; /** * Find all corresponding entities from the storage. * @param model Model type. * @param query Query filter. * @param select Fields to select. * @param options Find options. * @returns Returns a promise to get the list of entities found or undefined when an error occurs. */ find(model: Types.ModelClass, query: Filters.Query, select: string[], options: O): Promise; /** * Find the entity that corresponds to the specified entity Id. * @param model Model type. * @param id Entity Id. * @param select Fields to select. * @param options Find options. * @returns Returns a promise to get the entity found either undefined when the entity was not found or an error occurs. */ findById(model: Types.ModelClass, id: I, select: string[], options: O): Promise; /** * Update all entities that corresponds to the specified match. * @param model Model type. * @param match Matching filter. * @param entity Entity data. * @param options Update options. * @returns Returns a promise to get the number of updated entities or undefined when an error occurs. */ update(model: Types.ModelClass, match: Filters.Match, entity: E, options: O): Promise; /** * Update a entity that corresponds to the specified entity id. * @param model Model type. * @param id Entity id. * @param entity Entity data. * @param options Update options. * @returns Returns a promise to get true when the entity was updated either undefined when an error occurs or false otherwise. */ updateById(model: Types.ModelClass, id: I, entity: E, options: O): Promise; /** * Replace a entity that corresponds to the specified entity Id. * @param model Model type. * @param id Entity Id. * @param entity Entity data. * @param options Replace options. * @returns Returns a promise to get true when the entity was replaced either undefined when an error occurs or false otherwise. */ replaceById(model: Types.ModelClass, id: I, entity: E, options: O): Promise; /** * Delete all entities that corresponds to the specified match. * @param model Model type. * @param match Matching filter. * @param options Delete options. * @return Returns a promise to get the number of deleted entities or undefined when an error occurs. */ delete(model: Types.ModelClass, match: Filters.Match, options: O): Promise; /** * Delete the entity that corresponds to the specified entity Id. * @param model Model type. * @param id Entity Id. * @param options Delete options. * @return Returns a promise to get true when the entity was deleted either undefined when an error occurs or false otherwise. */ deleteById(model: Types.ModelClass, id: I, options: O): Promise; /** * Count all corresponding entities from the storage. * @param model Model type. * @param query Query filter. * @param options Count options. * @returns Returns a promise to get the total amount of found entities or undefined when an error occurs. */ count(model: Types.ModelClass, query: Filters.Query, options: O): Promise; }