Commit Graph

1056 Commits

Author SHA1 Message Date
Muhammad Aaqil 6ffad9f7d6 fix: add missing property in model generated
Signed-off-by: Muhammad Aaqil <aaqilniz@yahoo.com>

Update lib/datasource.js

Co-authored-by: Samarpan Bhattacharya <this.is.samy@gmail.com>
2022-11-04 09:20:07 -04:00
Samarpan Bhattacharya d29bec72a8 feat: add capability for insert multiple rows in single query
Signed-off-by: Samarpan Bhattacharya <this.is.samy@gmail.com>
2022-11-01 15:47:02 -04:00
Mario Estrada e3448fad03 chore: replace shortid with nanoid
Signed-off-by: Mario Estrada <marioestradarosa@yahoo.com>
2021-09-12 18:14:03 +08:00
Raymond Feng 454fd0f1b2 Fix value equality test to avoid toString
- The where statement can be something like {toString: 'not a function'}
- Avoid object string comparison

Signed-off-by: Raymond Feng <enjoyjava@gmail.com>
2020-10-30 09:15:39 -07:00
Matteo Padovano 76acf333fd
chore: add test for atomic upsertWithWhere (#1864)
Introduce the new property atomicUpsertWithWhere for
connector that implement specific method.
See https://github.com/strongloop/loopback-connector-mongodb/pull/563
for mongodb implementation.

Signed-off-by: Matteo Padovano <mrbatista@users.noreply.github.com>
2020-09-25 10:22:03 -04:00
Miroslav Bajtoš c884c62b3b
Add more `dataSource.execute()` flavors
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>
2020-08-03 15:00:30 +02:00
Miroslav Bajtoš c83f82d5a0
feat: implement DataSource.stop()
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>
2020-04-23 16:20:44 +02:00
Dimitris Xalatsis 095ddd654e
Add __parent reference to embedded models
Add a new hidden property `__parent` that's automatically set on all
instances of embedded models.

For backwards compatibility, this feature is not enabled by default.
You can turn it on by adding the following line to `server/server.js`
file:

    app.registry.modelBuilder.settings.parentRef = true;
2020-04-17 13:35:42 +02:00
Miroslav Bajtoš 04336a60cf
Add mocharc, remove mocha.opts
Mocha has deprecated `mocha.opts` in favour of RC files. See also
https://mochajs.org/#configuring-mocha-nodejs

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
2020-04-06 08:21:47 +02:00
Agnes Lin baeb76e911 allows diff db cols naming conventions 4 discover 2020-01-29 13:26:16 -05:00
Diana Lau 251ced811b
Update copyright year and CODEOWNERS (#1818)
* chore: update CODEOWNERS

* chore: update copyright years
2020-01-21 13:12:14 -05:00
Hage Yaapa b6f9e92ef8 feat: add persistDefaultValues (#1813)
Ignores value if it matches default value.
2019-12-17 10:52:15 -05:00
Jeremy Nagel b328934b6c [BUGFIX] Fix issue with with array constructor
- You can do new Array(4) to generate an array with 4 empty items
- Doing the same with list caused an error
- This broke lodash.deepclone
- This PR restores compatibility with the array constructor

Fixes #1798
2019-12-06 10:13:27 +11:00
Miroslav Bajtoš 1b7858a857
chore: update eslint to 6.x
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
2019-12-03 10:09:16 +01:00
Miroslav Bajtoš 770f11b3a6
Merge pull request #1790 from mitsos1os/return-promise-on-error
Convert error thrown by a property setter to a rejected promise
2019-11-29 10:15:52 +01:00
Hage Yaapa 89a964e919 feat: applyDefaultOnWrites in nested properties
Adds support for `applyDefaultOnWrites` in nested properties.
2019-11-28 13:59:47 +05:30
Dimitris Xalatsis b30fbf8c1e return failed promise on error 2019-11-22 19:38:43 +02:00
Francisco Buceta b9f0284a28
Fix generated string id's
Co-authored-by: Miroslav Bajtoš <mbajtoss@gmail.com>
2019-11-15 16:15:38 +01:00
Dimitris Halatsis ab11205fa0 fix #1781 (#1782) 2019-10-21 12:55:14 -04:00
Hage Yaapa 6f491dc756 chore: reduce identifier length
Existing identifier length exceeds Oracle DB's limit
2019-09-03 20:46:08 +05:30
Hage Yaapa 464610ef0a feat: add applyDefaultOnWrites property
Adds the ability to ignore writing default values to the database.
2019-08-19 17:11:27 +05:30
Ayeni Olusegun 814c55c7cd Fix polymorphic hasMany inverse relation (#1621)
* Polymorphic hasMany inverse relation

* rename test suit to eslint error
2019-08-12 15:30:28 -04:00
Dominique Emond bca631518b fix: prevent max listeners warning
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>
2019-08-09 09:03:51 -04:00
Miroslav Bajtoš f1fa976f50
Fix coercion of PK value in `replaceById` method
Before this change, when both the PK value (`id`) and the `data` object
were provided as plain-data values (e.g. as received in a JSON request),
and the connector was using a complex PK type (e.g. `ObjectID`
in MongoDB), then `replaceById` operation was printing confusing
warnings:

    WARNING: id property cannot be changed from 5d39775a59f5f541513c5e05
        to 5d39775a59f5f541513c5e05 for model:Post
        in 'before save' operation hook

    WARNING: id property cannot be changed from 5d39775a59f5f541513c5e05
        to 5d39775a59f5f541513c5e05 for model:Post
        in 'loaded' operation hook

This commit fixes the problem by applying the same type coercion on the
PK value (`id`) as has been applied by the model constructor on the PK
property (`data.id`).

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
2019-07-26 09:02:52 +02:00
Miroslav Bajtoš 78c5b12740
feat: add DataSource.deleteAllModels() API
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>
2019-07-18 17:56:41 +02:00
Miroslav Bajtoš 40286fcd28
fix: report errors from automigrate/autoupdate
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>
2019-07-04 12:36:50 +02:00
Biniam Admikew 1ed385e393 feat: add beginTransaction API on datasource
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>
2019-06-28 12:58:50 -04:00
Janny 58b3c4f148
test: add property index to support cloudant (#1750) 2019-06-19 14:36:48 -04:00
spurreiter 5b44c08f7a feat: after operation hook in case of errors
fix: move error into context

review: add debug statement; rename fns

fix: call next instead of ctx.end
2019-05-31 17:12:42 +02:00
Bill Matson 04523260c2 Fix for #1724 - Added options to attribute updates (#1725)
* Fix for #1724 - Added options to attribute updates

* Fix for #1724 - Added unit tests for options
2019-05-27 09:49:46 -04:00
Miroslav Bajtoš caf9d09274
Test "near" queries executed in memory
Rework setup of the Operation Hooks test suite for memory connector
so that the "unoptimized" variant disables not only atomic CRUD
operations, but also geo queries.

This way we can test both "near" querying implementations:
 - When the connectors supports "near" queries natively.
 - When "near" queries are executed at LoopBack side in-memory.
2019-05-14 09:14:10 +02:00
Miroslav Bajtoš 5369cf3d54
Fix DateString ctor to accept DateString instances
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
2019-05-13 15:21:00 +02:00
Miroslav Bajtoš ef0257e338
datasource: copy settings object in constructor
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.
2019-05-10 14:56:02 +02:00
Agnes Lin de4718d5b8 chore: update copyrights years (#1737) 2019-05-08 11:45:37 -04:00
biniam 9c94b9344b fix: allow coercion of nested properties
Handle model definitions with nested property
definitions for coercion of primitive values.
2019-05-03 18:45:39 -04:00
Miroslav Bajtoš b0e3de1083
Fix tests for empty/default values to pass on SQL 2019-05-03 08:57:48 +02:00
biniam eff6458a2a test: define models in before hooks
Re-work tests from #1702 based on the failures observed in #1719
and cherry-pick those commits back to master using ES6 syntax.
2019-04-30 11:15:23 -04:00
Miroslav Bajtoš 76673a8ed8
Update `should` to `13.2.3` 2019-04-30 11:44:08 +02:00
biniam 48af738ec4 fix: coerce primitive properties on update 2019-04-16 10:51:44 -04:00
biniam 1534392c62 fix: coerce date array properties 2019-04-16 10:50:54 -04:00
Miroslav Bajtoš fe83f3cfd1
Merge pull request #1581 from spurreiter/include-crashes
fix: normalize include with boolean or number
2019-04-12 17:05:02 +02:00
Miroslav Bajtoš 7d69bdab70
Improve tests for empty vs. default values 2019-04-09 15:54:52 +02:00
spurreiter 55b10a43c4 fix: normalize include with boolean or number
- On include = true or include = 1 the lib crashes with
  "TypeError: includes.forEach is not a function".
- checking for boolean and number type and return empty array.
- fix: include symbol and function in normalization
- fix: review changes; adding debug stmt + early exit for tests
2019-04-05 19:02:57 +02:00
Miroslav Bajtoš e45292de08
Do not apply default values on data from database
Before this change, when a property was configured with a default value
at LoopBack side and the database was returned a record with a missing
value for such property, then we would supply use the configured
default.

This behavior is problematic for reasons explained in #1692.

In this commit, we are fixing DAO operations like `find` and
`findOrCreate` so that they do NOT apply default property values on
data returned by the database (connector).

Please note that most of the other CRUD methods were already not
applying default values on database data as long as the connector
provided native implementation of the operation.
2019-04-04 09:47:31 +02:00
Hage Yaapa 80d8fcd8b1 feat: support array within array 2019-03-07 15:58:26 +05:30
Hage Yaapa a391c83a2c feat: Support "type" key in sub-properties 2019-02-21 13:58:34 +05:30
biniam 5e0c73bec7 fix: use correct callback for geo find queries 2019-02-14 15:45:13 -05:00
Miroslav Bajtoš fd99c6dc6e
Support nested properties with class type
When converting plain-data object values into model instances,
correctly handle the case where the constructor functions is a class
constructor and must be invoked via `new`.
2019-01-25 10:05:36 +01:00
biniam 0b81425a13 fix: use existing field in exclude test
Co-authored-by: Raymond Feng <rfeng@us.ibm.com>
2019-01-16 13:24:27 -05:00
Miroslav Bajtoš 9e0f624ad5
manually fix remaining problems 2018-12-07 16:46:15 +01:00