UNPKG

5.54 kBTypeScriptView Raw
1import { Filter, Where } from '@loopback/filter';
2import { Class, Count, Options } from '../common-types';
3import { Entity, EntityData } from '../model';
4import { Connector } from './connector';
5/**
6 * CRUD operations for connector implementations
7 */
8export interface CrudConnector extends Connector {
9 /**
10 * Create a new entity
11 * @param modelClass - The model class
12 * @param entity - The entity instance or data
13 * @param options - Options for the operation
14 * @returns A promise of the entity created
15 */
16 create(modelClass: Class<Entity>, entity: EntityData, options?: Options): Promise<EntityData>;
17 /**
18 * Create multiple entities
19 * @param modelClass - The model class
20 * @param entities - An array of entity instances or data
21 * @param options - Options for the operation
22 * @returns A promise of an array of entities created
23 */
24 createAll?(modelClass: Class<Entity>, entities: EntityData[], options?: Options): Promise<EntityData[]>;
25 /**
26 * Save an entity
27 * @param modelClass - The model class
28 * @param entity - The entity instance or data
29 * @param options - Options for the operation
30 * @returns A promise of the entity saved
31 */
32 save?(modelClass: Class<Entity>, entity: EntityData, options?: Options): Promise<EntityData>;
33 /**
34 * Find matching entities by the filter
35 * @param modelClass - The model class
36 * @param filter - The query filter
37 * @param options - Options for the operation
38 * @returns A promise of an array of entities found for the filter
39 */
40 find(modelClass: Class<Entity>, filter?: Filter, options?: Options): Promise<EntityData[]>;
41 /**
42 * Find an entity by id
43 * @param modelClass - The model class
44 * @param id - The entity id value
45 * @param options - Options for the operation
46 * @returns A promise of the entity found for the id
47 */
48 findById?<IdType>(modelClass: Class<Entity>, id: IdType, options?: Options): Promise<EntityData>;
49 /**
50 * Update an entity
51 * @param modelClass - The model class
52 * @param entity - The entity instance or data
53 * @param options - Options for the operation
54 * @returns Promise<true> if an entity is updated, otherwise
55 * Promise<false>
56 */
57 update?(modelClass: Class<Entity>, entity: EntityData, options?: Options): Promise<boolean>;
58 /**
59 * Delete an entity
60 * @param modelClass - The model class
61 * @param entity - The entity instance or data
62 * @param options - Options for the operation
63 * @returns Promise<true> if an entity is deleted, otherwise
64 * Promise<false>
65 */
66 delete?(modelClass: Class<Entity>, entity: EntityData, options?: Options): Promise<boolean>;
67 /**
68 * Update matching entities
69 * @param modelClass - The model class
70 * @param data - The data attributes to be updated
71 * @param where - The matching criteria
72 * @param options - Options for the operation
73 * @returns A promise of number of matching entities deleted
74 */
75 updateAll(modelClass: Class<Entity>, data: EntityData, where?: Where<Entity>, options?: Options): Promise<Count>;
76 /**
77 * Update an entity by id
78 * @param modelClass - The model class
79 * @param id - The entity id value
80 * @param data - The data attributes to be updated
81 * @param options - Options for the operation
82 * @returns Promise<true> if an entity is updated for the id, otherwise
83 * Promise<false>
84 */
85 updateById?<IdType>(modelClass: Class<Entity>, id: IdType, data: EntityData, options?: Options): Promise<boolean>;
86 /**
87 * Replace an entity by id
88 * @param modelClass - The model class
89 * @param id - The entity id value
90 * @param data - The data attributes to be updated
91 * @param options - Options for the operation
92 * @returns Promise<true> if an entity is replaced for the id, otherwise
93 * Promise<false>
94 */
95 replaceById?<IdType>(modelClass: Class<Entity>, id: IdType, data: EntityData, options?: Options): Promise<boolean>;
96 /**
97 * Delete matching entities
98 * @param modelClass - The model class
99 * @param where - The matching criteria
100 * @param options - Options for the operation
101 * @returns A promise of number of matching entities deleted
102 */
103 deleteAll(modelClass: Class<Entity>, where?: Where<Entity>, options?: Options): Promise<Count>;
104 /**
105 * Delete an entity by id
106 * @param modelClass - The model class
107 * @param id - The entity id value
108 * @param options - Options for the operation
109 * @returns Promise<true> if an entity is deleted for the id, otherwise
110 * Promise<false>
111 */
112 deleteById?<IdType>(modelClass: Class<Entity>, id: IdType, options?: Options): Promise<boolean>;
113 /**
114 * Count matching entities
115 * @param modelClass - The model class
116 * @param where - The matching criteria
117 * @param options - Options for the operation
118 * @returns A promise of number of matching entities
119 */
120 count(modelClass: Class<Entity>, where?: Where<Entity>, options?: Options): Promise<Count>;
121 /**
122 * Check if an entity exists for the id
123 * @param modelClass - The model class
124 * @param id - The entity id value
125 * @param options - Options for the operation
126 * @returns Promise<true> if an entity exists for the id, otherwise
127 * Promise<false>
128 */
129 exists?<IdType>(modelClass: Class<Entity>, id: IdType, options?: Options): Promise<boolean>;
130}