1 | // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
|
2 | // Node module: @loopback/repository
|
3 | // This file is licensed under the MIT License.
|
4 | // License text available at https://opensource.org/licenses/MIT
|
5 |
|
6 | import {Filter, Where} from '@loopback/filter';
|
7 | import {Class, Count, Options} from '../common-types';
|
8 | import {Entity, EntityData} from '../model';
|
9 | import {Connector} from './connector';
|
10 |
|
11 | /**
|
12 | * CRUD operations for connector implementations
|
13 | */
|
14 | export interface CrudConnector extends Connector {
|
15 | /**
|
16 | * Create a new entity
|
17 | * @param modelClass - The model class
|
18 | * @param entity - The entity instance or data
|
19 | * @param options - Options for the operation
|
20 | * @returns A promise of the entity created
|
21 | */
|
22 | create(
|
23 | modelClass: Class<Entity>,
|
24 | entity: EntityData,
|
25 | options?: Options,
|
26 | ): Promise<EntityData>;
|
27 |
|
28 | /**
|
29 | * Create multiple entities
|
30 | * @param modelClass - The model class
|
31 | * @param entities - An array of entity instances or data
|
32 | * @param options - Options for the operation
|
33 | * @returns A promise of an array of entities created
|
34 | */
|
35 | createAll?(
|
36 | modelClass: Class<Entity>,
|
37 | entities: EntityData[],
|
38 | options?: Options,
|
39 | ): Promise<EntityData[]>;
|
40 |
|
41 | /**
|
42 | * Save an entity
|
43 | * @param modelClass - The model class
|
44 | * @param entity - The entity instance or data
|
45 | * @param options - Options for the operation
|
46 | * @returns A promise of the entity saved
|
47 | */
|
48 | save?(
|
49 | modelClass: Class<Entity>,
|
50 | entity: EntityData,
|
51 | options?: Options,
|
52 | ): Promise<EntityData>;
|
53 |
|
54 | /**
|
55 | * Find matching entities by the filter
|
56 | * @param modelClass - The model class
|
57 | * @param filter - The query filter
|
58 | * @param options - Options for the operation
|
59 | * @returns A promise of an array of entities found for the filter
|
60 | */
|
61 | find(
|
62 | modelClass: Class<Entity>,
|
63 | filter?: Filter,
|
64 | options?: Options,
|
65 | ): Promise<EntityData[]>;
|
66 |
|
67 | /**
|
68 | * Find an entity by id
|
69 | * @param modelClass - The model class
|
70 | * @param id - The entity id value
|
71 | * @param options - Options for the operation
|
72 | * @returns A promise of the entity found for the id
|
73 | */
|
74 | findById?<IdType>(
|
75 | modelClass: Class<Entity>,
|
76 | id: IdType,
|
77 | options?: Options,
|
78 | ): Promise<EntityData>;
|
79 |
|
80 | /**
|
81 | * Update an entity
|
82 | * @param modelClass - The model class
|
83 | * @param entity - The entity instance or data
|
84 | * @param options - Options for the operation
|
85 | * @returns Promise<true> if an entity is updated, otherwise
|
86 | * Promise<false>
|
87 | */
|
88 | update?(
|
89 | modelClass: Class<Entity>,
|
90 | entity: EntityData,
|
91 | options?: Options,
|
92 | ): Promise<boolean>;
|
93 |
|
94 | /**
|
95 | * Delete an entity
|
96 | * @param modelClass - The model class
|
97 | * @param entity - The entity instance or data
|
98 | * @param options - Options for the operation
|
99 | * @returns Promise<true> if an entity is deleted, otherwise
|
100 | * Promise<false>
|
101 | */
|
102 | delete?(
|
103 | modelClass: Class<Entity>,
|
104 | entity: EntityData,
|
105 | options?: Options,
|
106 | ): Promise<boolean>;
|
107 |
|
108 | /**
|
109 | * Update matching entities
|
110 | * @param modelClass - The model class
|
111 | * @param data - The data attributes to be updated
|
112 | * @param where - The matching criteria
|
113 | * @param options - Options for the operation
|
114 | * @returns A promise of number of matching entities deleted
|
115 | */
|
116 | updateAll(
|
117 | modelClass: Class<Entity>,
|
118 | data: EntityData,
|
119 | where?: Where<Entity>,
|
120 | options?: Options,
|
121 | ): Promise<Count>;
|
122 |
|
123 | /**
|
124 | * Update an entity by id
|
125 | * @param modelClass - The model class
|
126 | * @param id - The entity id value
|
127 | * @param data - The data attributes to be updated
|
128 | * @param options - Options for the operation
|
129 | * @returns Promise<true> if an entity is updated for the id, otherwise
|
130 | * Promise<false>
|
131 | */
|
132 | updateById?<IdType>(
|
133 | modelClass: Class<Entity>,
|
134 | id: IdType,
|
135 | data: EntityData,
|
136 | options?: Options,
|
137 | ): Promise<boolean>;
|
138 |
|
139 | /**
|
140 | * Replace an entity by id
|
141 | * @param modelClass - The model class
|
142 | * @param id - The entity id value
|
143 | * @param data - The data attributes to be updated
|
144 | * @param options - Options for the operation
|
145 | * @returns Promise<true> if an entity is replaced for the id, otherwise
|
146 | * Promise<false>
|
147 | */
|
148 | replaceById?<IdType>(
|
149 | modelClass: Class<Entity>,
|
150 | id: IdType,
|
151 | data: EntityData,
|
152 | options?: Options,
|
153 | ): Promise<boolean>;
|
154 |
|
155 | /**
|
156 | * Delete matching entities
|
157 | * @param modelClass - The model class
|
158 | * @param where - The matching criteria
|
159 | * @param options - Options for the operation
|
160 | * @returns A promise of number of matching entities deleted
|
161 | */
|
162 | deleteAll(
|
163 | modelClass: Class<Entity>,
|
164 | where?: Where<Entity>,
|
165 | options?: Options,
|
166 | ): Promise<Count>;
|
167 |
|
168 | /**
|
169 | * Delete an entity by id
|
170 | * @param modelClass - The model class
|
171 | * @param id - The entity id value
|
172 | * @param options - Options for the operation
|
173 | * @returns Promise<true> if an entity is deleted for the id, otherwise
|
174 | * Promise<false>
|
175 | */
|
176 | deleteById?<IdType>(
|
177 | modelClass: Class<Entity>,
|
178 | id: IdType,
|
179 | options?: Options,
|
180 | ): Promise<boolean>;
|
181 |
|
182 | /**
|
183 | * Count matching entities
|
184 | * @param modelClass - The model class
|
185 | * @param where - The matching criteria
|
186 | * @param options - Options for the operation
|
187 | * @returns A promise of number of matching entities
|
188 | */
|
189 | count(
|
190 | modelClass: Class<Entity>,
|
191 | where?: Where<Entity>,
|
192 | options?: Options,
|
193 | ): Promise<Count>;
|
194 |
|
195 | /**
|
196 | * Check if an entity exists for the id
|
197 | * @param modelClass - The model class
|
198 | * @param id - The entity id value
|
199 | * @param options - Options for the operation
|
200 | * @returns Promise<true> if an entity exists for the id, otherwise
|
201 | * Promise<false>
|
202 | */
|
203 | exists?<IdType>(
|
204 | modelClass: Class<Entity>,
|
205 | id: IdType,
|
206 | options?: Options,
|
207 | ): Promise<boolean>;
|
208 | }
|