Change the return value of `DataSource.stop()` from `Promise<void>`
to `void | PromiseLike<void>` to avoid breaking existing LoopBack 4
applications, where DataSource subclasses are scaffolded with
`stop(): ValueOrPromise<void>`.
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
Implement `stop` as an alias for `disconnect`. This way LB4 applications
don't have to include custom `stop` implementation in every datasource
file.
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
Remove usage of `PromiseOrVoid`, it makes it difficult to consume
the API via `await`. For each async method, define multiple variants
to correctly describe what's returned when a callback arg was provided
(`void`) and what's returned when called with no callback
(`Promise<T>`).
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
When writing tests, for performance reasons we often want to reuse
the same data-source instance for many tests suites. At the same time,
we want to keep such test suites independent and allow them to reuse
the same model name for different model classes.
Juggler does support redefinition of a model with the same name.
This change is adding a new API called that allows tests to remove all
old models before creating new ones. This API would be typically
called from a `before` hook.
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
add beginTransaction method which calls begin
method from the Transaction class which in turn
calls the connector's beginTransaction method if
it supports transactions.
Co-Authored-By: Miroslav Bajtoš <mbajtoss@gmail.com>
Use case:
1. Configure a datasource with lazyConnect = true
2. Do NOT start the DB
3. Start the app
4. Send first request and it fails to connnect to the DB
5. Start the DB
5. Requests are now served correctly