1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import {AnyObject, Callback, Options} from './common';
|
7 | import {Connector} from './connector';
|
8 | import {
|
9 | ModelBaseClass,
|
10 | ModelBuilder,
|
11 | ModelDefinition,
|
12 | PropertyDefinition
|
13 | } from './model';
|
14 | import {EventEmitter} from 'events';
|
15 | import {IsolationLevel, Transaction} from './transaction-mixin';
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | export declare class DataSource extends EventEmitter {
|
78 | name: string;
|
79 | settings: Options;
|
80 |
|
81 | initialized?: boolean;
|
82 | connected?: boolean;
|
83 | connecting?: boolean;
|
84 |
|
85 | connector?: Connector;
|
86 |
|
87 | definitions: {[modelName: string]: ModelDefinition};
|
88 |
|
89 | DataAccessObject: AnyObject & {prototype: AnyObject};
|
90 |
|
91 | constructor(name: string, settings?: Options, modelBuilder?: ModelBuilder);
|
92 |
|
93 | constructor(settings?: Options, modelBuilder?: ModelBuilder);
|
94 |
|
95 | constructor(
|
96 | connectorModule: Connector,
|
97 | settings?: Options,
|
98 | modelBuilder?: ModelBuilder,
|
99 | );
|
100 |
|
101 | /**
|
102 | * Create a model class
|
103 | * @param name Name of the model
|
104 | * @param properties An object of property definitions
|
105 | * @param options Options for model settings
|
106 | */
|
107 | createModel<T extends ModelBaseClass>(
|
108 | name: string,
|
109 | properties?: AnyObject,
|
110 | options?: Options,
|
111 | ): T;
|
112 |
|
113 | /**
|
114 | * Look up a model class by name
|
115 | * @param modelName Model name
|
116 | * @param forceCreate A flag to force creation of a model if not found
|
117 | */
|
118 | getModel(
|
119 | modelName: string,
|
120 | forceCreate?: boolean,
|
121 | ): ModelBaseClass | undefined;
|
122 |
|
123 | /**
|
124 | * Remove a model from the registry.
|
125 | *
|
126 | * @param modelName
|
127 | */
|
128 | deleteModelByName(modelName: string): void;
|
129 |
|
130 | /**
|
131 | * Remove all models from the registry, but keep the connector instance
|
132 | * (including the pool of database connections).
|
133 | */
|
134 | deleteAllModels(): void;
|
135 |
|
136 | /**
|
137 | * Attach an existing model to a data source.
|
138 | * This will mixin all of the data access object functions (DAO) into your
|
139 | * modelClass definition.
|
140 | * @param {ModelBaseClass} modelClass The model constructor that will be enhanced
|
141 | * by DataAccessObject mixins.
|
142 | */
|
143 | attach(modelClass: ModelBaseClass): ModelBaseClass;
|
144 |
|
145 | automigrate(models?: string | string[]): Promise<void>;
|
146 | // legacy callback style
|
147 | automigrate(models: string | string[] | undefined, callback: Callback): void;
|
148 |
|
149 | autoupdate(models?: string | string[]): Promise<void>;
|
150 | // legacy callback style
|
151 | autoupdate(models: string | string[] | undefined, callback: Callback): void;
|
152 |
|
153 | discoverModelDefinitions(
|
154 | options?: Options,
|
155 | ): Promise<ModelDefinition[]>;
|
156 | // legacy callback style (no options)
|
157 | discoverModelDefinitions(
|
158 | callback: Callback<ModelDefinition[]>,
|
159 | ): void;
|
160 | // legacy callback style (with options)
|
161 | discoverModelDefinitions(
|
162 | options: Options,
|
163 | callback: Callback<ModelDefinition[]>,
|
164 | ): void;
|
165 |
|
166 | discoverModelProperties(
|
167 | modelName: string,
|
168 | options?: Options,
|
169 | ): Promise<PropertyDefinition[]>;
|
170 | // legacy callback style (no options)
|
171 | discoverModelProperties(
|
172 | modelName: string,
|
173 | callback: Callback<PropertyDefinition[]>,
|
174 | ): void;
|
175 | // legacy callback style (with options)
|
176 | discoverModelProperties(
|
177 | modelName: string,
|
178 | options: Options,
|
179 | callback: Callback<PropertyDefinition[]>,
|
180 | ): void;
|
181 |
|
182 | discoverPrimaryKeys(
|
183 | modelName: string,
|
184 | options?: Options,
|
185 | ): Promise<PropertyDefinition[]>;
|
186 | // legacy callback style (no options)
|
187 | discoverPrimaryKeys(
|
188 | modelName: string,
|
189 | callback: Callback<PropertyDefinition[]>,
|
190 | ): void;
|
191 | // legacy callback style (with options)
|
192 | discoverPrimaryKeys(
|
193 | modelName: string,
|
194 | options: Options,
|
195 | callback: Callback<PropertyDefinition[]>,
|
196 | ): void;
|
197 |
|
198 | discoverForeignKeys(
|
199 | modelName: string,
|
200 | options?: Options,
|
201 | ): Promise<PropertyDefinition[]>;
|
202 | // legacy callback style (no options)
|
203 | discoverForeignKeys(
|
204 | modelName: string,
|
205 | callback: Callback<PropertyDefinition[]>,
|
206 | ): void;
|
207 | // legacy callback style (with options)
|
208 | discoverForeignKeys(
|
209 | modelName: string,
|
210 | options: Options,
|
211 | callback: Callback<PropertyDefinition[]>,
|
212 | ): void;
|
213 |
|
214 | discoverExportedForeignKeys(
|
215 | modelName: string,
|
216 | options?: Options,
|
217 | ): Promise<PropertyDefinition[]>;
|
218 | // legacy callback style (no options)
|
219 | discoverExportedForeignKeys(
|
220 | modelName: string,
|
221 | callback: Callback<PropertyDefinition[]>,
|
222 | ): void;
|
223 | // legacy callback style (with options)
|
224 | discoverExportedForeignKeys(
|
225 | modelName: string,
|
226 | options: Options,
|
227 | callback: Callback<PropertyDefinition[]>,
|
228 | ): void;
|
229 |
|
230 | discoverAndBuildModels(
|
231 | modelName: string,
|
232 | options?: Options,
|
233 | ): Promise<{[name: string]: ModelBaseClass}>;
|
234 | // legacy callback style (no options)
|
235 | discoverAndBuildModels(
|
236 | modelName: string,
|
237 | callback: Callback<{[name: string]: ModelBaseClass}>,
|
238 | ): void;
|
239 | // legacy callback style (with options)
|
240 | discoverAndBuildModels(
|
241 | modelName: string,
|
242 | options: Options,
|
243 | callback: Callback<{[name: string]: ModelBaseClass}>,
|
244 | ): void;
|
245 |
|
246 | discoverSchema(
|
247 | tableName: string,
|
248 | options?: Options,
|
249 | ): Promise<AnyObject>;
|
250 | // legacy callback style (no options)
|
251 | discoverSchema(
|
252 | tableName: string,
|
253 | callback: Callback<AnyObject>,
|
254 | ): void;
|
255 | // legacy callback style (with options)
|
256 | discoverSchema(
|
257 | tableName: string,
|
258 | options: Options,
|
259 | callback: Callback<AnyObject>,
|
260 | ): void;
|
261 |
|
262 | discoverSchemas(
|
263 | tableName: string,
|
264 | options?: Options,
|
265 | ): Promise<AnyObject[]>;
|
266 | // legacy callback style (no options)
|
267 | discoverSchemas(
|
268 | tableName: string,
|
269 | callback: Callback<AnyObject[]>,
|
270 | ): void;
|
271 | // legacy callback style (with options)
|
272 | discoverSchemas(
|
273 | tableName: string,
|
274 | options: Options,
|
275 | callback: Callback<AnyObject[]>,
|
276 | ): void;
|
277 |
|
278 | buildModelFromInstance(
|
279 | modelName: string,
|
280 | jsonObject: AnyObject,
|
281 | options?: Options,
|
282 | ): ModelBaseClass;
|
283 |
|
284 | connect(): Promise<void>;
|
285 | // legacy callback style
|
286 | connect(callback: Callback): void;
|
287 |
|
288 | disconnect(): Promise<void>;
|
289 | // legacy callback style
|
290 | disconnect(callback: Callback): void;
|
291 |
|
292 | // Only promise variant, callback is intentionally not described.
|
293 | // Note we must use `void | PromiseLike<void>` to avoid breaking
|
294 | // existing LoopBack 4 applications.
|
295 | // TODO(semver-major): change the return type to `Promise<void>`
|
296 | stop(): void | PromiseLike<void>;
|
297 |
|
298 | ping(): Promise<void>;
|
299 | // legacy callback style
|
300 | ping(callback: Callback): void;
|
301 |
|
302 | // Only promise variant, callback is intentionally not supported.
|
303 |
|
304 | /**
|
305 | * Execute a SQL command.
|
306 | *
|
307 | * **WARNING:** In general, it is always better to perform database actions
|
308 | * through repository methods. Directly executing SQL may lead to unexpected
|
309 | * results, corrupted data, security vulnerabilities and other issues.
|
310 | *
|
311 | * @example
|
312 | *
|
313 | * ```ts
|
314 | * // MySQL
|
315 | * const result = await db.execute(
|
316 | * 'SELECT * FROM Products WHERE size > ?',
|
317 | * [42]
|
318 | * );
|
319 | *
|
320 | * // PostgreSQL
|
321 | * const result = await db.execute(
|
322 | * 'SELECT * FROM Products WHERE size > $1',
|
323 | * [42]
|
324 | * );
|
325 | * ```
|
326 | *
|
327 | * @param command A parameterized SQL command or query.
|
328 | * Check your database documentation for information on which characters to
|
329 | * use as parameter placeholders.
|
330 | * @param parameters List of parameter values to use.
|
331 | * @param options Additional options, for example `transaction`.
|
332 | * @returns A promise which resolves to the command output as returned by the
|
333 | * database driver. The output type (data structure) is database specific and
|
334 | * often depends on the command executed.
|
335 | */
|
336 | execute(
|
337 | command: string | object,
|
338 | parameters?: any[] | object,
|
339 | options?: Options,
|
340 | ): Promise<any>;
|
341 |
|
342 | /**
|
343 | * Execute a MongoDB command.
|
344 | *
|
345 | * **WARNING:** In general, it is always better to perform database actions
|
346 | * through repository methods. Directly executing MongoDB commands may lead
|
347 | * to unexpected results and other issues.
|
348 | *
|
349 | * @example
|
350 | *
|
351 | * ```ts
|
352 | * const result = await db.execute('MyCollection', 'aggregate', [
|
353 | * {$lookup: {
|
354 | *
|
355 | * }},
|
356 | * {$unwind: '$data'},
|
357 | * {$out: 'tempData'}
|
358 | * ]);
|
359 | * ```
|
360 | *
|
361 | * @param collectionName The name of the collection to execute the command on.
|
362 | * @param command The command name. See
|
363 | * [Collection API docs](http:
|
364 | * for the list of commands supported by the MongoDB client.
|
365 | * @param parameters Command parameters (arguments), as described in MongoDB API
|
366 | * docs for individual collection methods.
|
367 | * @returns A promise which resolves to the command output as returned by the
|
368 | * database driver.
|
369 | */
|
370 | execute(
|
371 | collectionName: string,
|
372 | command: string,
|
373 | ...parameters: any[],
|
374 | ): Promise<any>;
|
375 |
|
376 | |
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 | execute(...args: any[]): Promise<any>;
|
390 |
|
391 | |
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 | beginTransaction(options?: IsolationLevel | Options): Promise<Transaction>;
|
399 | }
|
400 |
|
\ | No newline at end of file |