Implement support for the following variants:
- `execute(collection, command, ...params, options)` (MongoDB)
- `execute(...params)` (forward-compatibility & other databases)
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>
If establishing a database connection is slow
and database migration runs and there are many
models, sql operations are queued up and this
leads to the node.js max emitters exceeded
warning.
A default value for max emitters has now
been introduced, and it can also be configured
in datasources.json.
Co-authored-by: Dominique Emond <dremond@ca.ibm.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>
Defer automigrate/autoupdate until we are connected, so that connection
errors can be reported back to callers.
Fix postInit handler to not report connection error to console.log
and via dataSource "error" event in case there is already an operation
queued. When this happens, we want the error to be handled by the
queued operation and reported to its caller.
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
Fix DataSource constructor to create a shallow copy of the settings
object provided by the caller. This prevents surprising behavior
where changes made to `ds.settings` were picked up by the provided
config object, as observed e.g. in tests of our MongoDB connector.
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
Add API allowing consumers (e.g. LoopBack) to remove a Model from all
juggler registries:
- ModelBuilder's models
- ModelBuilder's definitions
- Connector registry of models
Before this change, when resolving full connector path, all errors were
ignored. As a result, when the connector was installed but not
correctly built (e.g. loopback-connector-db2 which uses a native addon),
a very confusing message was reported by LoopBack.
In this commit, I am fixing the code handling `require()` errors
to ignore only MODULE_NOT_FOUND errors that contain the name
of the required module.