// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved. // Node module: @loopback/repository // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT import {Filter, Where} from '@loopback/filter'; import {Class, Count, Options} from '../common-types'; import {Entity, EntityData} from '../model'; import {Connector} from './connector'; /** * CRUD operations for connector implementations */ export interface CrudConnector extends Connector { /** * Create a new entity * @param modelClass - The model class * @param entity - The entity instance or data * @param options - Options for the operation * @returns A promise of the entity created */ create( modelClass: Class, entity: EntityData, options?: Options, ): Promise; /** * Create multiple entities * @param modelClass - The model class * @param entities - An array of entity instances or data * @param options - Options for the operation * @returns A promise of an array of entities created */ createAll?( modelClass: Class, entities: EntityData[], options?: Options, ): Promise; /** * Save an entity * @param modelClass - The model class * @param entity - The entity instance or data * @param options - Options for the operation * @returns A promise of the entity saved */ save?( modelClass: Class, entity: EntityData, options?: Options, ): Promise; /** * Find matching entities by the filter * @param modelClass - The model class * @param filter - The query filter * @param options - Options for the operation * @returns A promise of an array of entities found for the filter */ find( modelClass: Class, filter?: Filter, options?: Options, ): Promise; /** * Find an entity by id * @param modelClass - The model class * @param id - The entity id value * @param options - Options for the operation * @returns A promise of the entity found for the id */ findById?( modelClass: Class, id: IdType, options?: Options, ): Promise; /** * Update an entity * @param modelClass - The model class * @param entity - The entity instance or data * @param options - Options for the operation * @returns Promise if an entity is updated, otherwise * Promise */ update?( modelClass: Class, entity: EntityData, options?: Options, ): Promise; /** * Delete an entity * @param modelClass - The model class * @param entity - The entity instance or data * @param options - Options for the operation * @returns Promise if an entity is deleted, otherwise * Promise */ delete?( modelClass: Class, entity: EntityData, options?: Options, ): Promise; /** * Update matching entities * @param modelClass - The model class * @param data - The data attributes to be updated * @param where - The matching criteria * @param options - Options for the operation * @returns A promise of number of matching entities deleted */ updateAll( modelClass: Class, data: EntityData, where?: Where, options?: Options, ): Promise; /** * Update an entity by id * @param modelClass - The model class * @param id - The entity id value * @param data - The data attributes to be updated * @param options - Options for the operation * @returns Promise if an entity is updated for the id, otherwise * Promise */ updateById?( modelClass: Class, id: IdType, data: EntityData, options?: Options, ): Promise; /** * Replace an entity by id * @param modelClass - The model class * @param id - The entity id value * @param data - The data attributes to be updated * @param options - Options for the operation * @returns Promise if an entity is replaced for the id, otherwise * Promise */ replaceById?( modelClass: Class, id: IdType, data: EntityData, options?: Options, ): Promise; /** * Delete matching entities * @param modelClass - The model class * @param where - The matching criteria * @param options - Options for the operation * @returns A promise of number of matching entities deleted */ deleteAll( modelClass: Class, where?: Where, options?: Options, ): Promise; /** * Delete an entity by id * @param modelClass - The model class * @param id - The entity id value * @param options - Options for the operation * @returns Promise if an entity is deleted for the id, otherwise * Promise */ deleteById?( modelClass: Class, id: IdType, options?: Options, ): Promise; /** * Count matching entities * @param modelClass - The model class * @param where - The matching criteria * @param options - Options for the operation * @returns A promise of number of matching entities */ count( modelClass: Class, where?: Where, options?: Options, ): Promise; /** * Check if an entity exists for the id * @param modelClass - The model class * @param id - The entity id value * @param options - Options for the operation * @returns Promise if an entity exists for the id, otherwise * Promise */ exists?( modelClass: Class, id: IdType, options?: Options, ): Promise; }