Commit Graph

188 Commits

Author SHA1 Message Date
Raymond Feng 87e1e217c3 fix: allow `new DataSource(connector, settings)` 2018-02-13 09:42:41 -08:00
Raymond Feng 4be2ea8afb fix: add more tests to verify new DataSource() 2018-02-09 14:33:42 -08:00
Raymond Feng 9d3e6cd8f5 Merge branch 'set-datasource-name' of https://github.com/truongminh/loopback-datasource-juggler into truongminh-set-datasource-name 2018-02-07 16:50:57 -08:00
Nguyen Truong Minh 80f9364edc feat(datasource): seperate name and connector name 2018-02-07 16:25:25 +07:00
Kevin Scroggins 25b1aa5abc Fix datasource not correctly retaining name value 2018-01-31 11:30:24 -05:00
Kevin Scroggins 92595b4348
Add warning for datasources with mismatched names 2018-01-23 14:18:49 +01:00
zbarbuto f5de99b249 Allow new transaction method in postgresql (#1493)
kv-extreme-scale needs fixing, unrelated.
2017-12-12 10:56:42 -05:00
Jürg Lehni 0ce1fa9f87 Add a better way to handle transactions 2017-09-06 07:10:57 +02:00
Rashmi Hunt 6c6df15286 Flag id as updateOnly when forceId is in effect (#1453)
* updateOnly, forceId changes

* support getUpdateOnlyProperties

* fixup! fix updateOrCreate in forceId mode

The contract of `updateOrCreate` is expecting a full object instance
to be passed to the callback.

The current implementation was creating an empty instance and
calling updateAttributes under the hood. As a result, the callback
was called with the attributes being updated only.

In order to preserve existing behaviour, we have to always build
a full initial instance by calling `findById`.

See the following discussion for more context:
https://github.com/strongloop/loopback-datasource-juggler/issues/966

* fixup! fix tests of upsert validation

* move forceId to model-builder

* remove TODO comment

* revert refactoring and test fixes

* Remove duplicate test

* change testcase names

* change to ModeClass.settingse

* forceId setup from datasource to model-builder

* fix inheritance of auto-generated forceId

* Fixed failing tests for auto change

* fixed a comment
2017-08-22 13:09:45 -07:00
Rand McKinney 0a056adee4 Remove spurious extra options arg (#1390)
* Remove spurious extra options arg

* Remove space
2017-05-26 11:34:50 -07:00
ebarault cfd3cdf535 Overall review of polymorphic relations
In #1298, the spec/doc for polymorphic relations was reviewed

**hasX relation**
- `type`: **hasMany**
- `as`: redefines **this** relation's name (optional)
- `model`: **modelTo**
- `polymorphic`:
  - typeOf `polymorphic` === `String`
    - matching **belongsTo** relation name
      - `foreignKey` is generated as `polymorphic + 'Id'`,
      - `discriminator` is generated as `polymorphic + 'Type'`
  - typeOf `polymorphic` === `Object`
    - `as`: **DEPRECATED** should display a warning,
            replaced by `selector`
    - `selector`: should match **belongsTo** relation name if the
                  latter is defined with {polymorphic: true}
      - (required) if both foreignKey and discriminator
        are **NOT** provided
      - (extraneous) if both foreignKey and discriminator
        are provided
    - `foreignKey`:  A property of modelTo, representing the fk to
       modelFrom's id.
      - generated by default as `selector + 'Id'`
    - `discriminator`: A property of modelTo, representing the actual
                       modelFrom to be looked up and defined
                       dynamically
      - generated by default as `selector + 'Type'`

---

**belongsTo relation**
- `type`: **belongsTo**
- `as`: redefines **this** relation's name (optional)
- `model`: **NOT EXPECTED**: should throw an error at
               relation validation
- `polymorphic`:
  - typeOf `polymorphic` === `Boolean`
      - `foreignKey` is generated as `relationName + 'Id'`,
      - `discriminator` is generated as `relationName + 'Type'`
  - typeOf `polymorphic` === `Object`
    - `as`: **DEPRECATED**: should display a warning,
            replaced by `selector`
    - `selector`:
      - (required) if both foreignKey and discriminator
        are **NOT** provided
      - (extraneous) if both foreignKey and discriminator
        are provided
    - `foreignKey`: A property of modelTo, representing the fk to
                    modelFrom's id.
      - generated by default as `selector + 'Id'`
    - `discriminator`: A property of modelTo, representing the actual
                       modelFrom to be looked up and defined
                       dynamically
      - generated by default as `selector + 'Type'`
2017-05-12 21:33:39 +02:00
Loay ef61c8618a Update api documents 2017-04-27 16:28:43 -04:00
Kevin Delisle f7fe187120 Datasource documentation tune-up 2017-04-25 15:51:42 -04:00
Sakib Hasan 6a962583b0 Support multiple fk relations (#1308) 2017-04-04 18:23:43 -04:00
Raymond Feng 1f995ec674 Use dataSource.connect to avoid duplicate connects 2017-04-04 10:19:58 -07:00
Raymond Feng 0a408476ec Fix in-mem connector file operation racing condition 2017-04-04 08:25:15 -07:00
jannyHou 7373e1ae31 Doc:Add option for discoverModelDefinitions 2017-03-14 21:51:30 -04:00
Miroslav Bajtoš e8a977f55b Fix datasource to report connector-loading errors
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.
2017-02-03 20:29:11 +01:00
Brian Schemp cd94be2fb8 Throw error when model relation name is trigger
Defining a model relation with the name "trigger" causes the model not
able to insert records. No error is thrown when a model relation with
the name "trigger" is defined. Adding a check for the model relation
name "trigger" will now throw an error.
2017-01-02 17:09:14 +01:00
Amir Jafarian 2830062259 Disable `strict` for a few files
*Disable `strict` for a few files to disappear warnings
2016-08-26 09:54:31 -04:00
Amir Jafarian c17a490708 Fix CI introduced by `use strict` 2016-08-25 09:49:02 -04:00
Amir Jafarian aec678d252 Fix manually 2016-08-22 19:20:12 -04:00
Amir Jafarian aa6d28268b Auto-update by eslint --fix 2016-08-22 15:12:25 -04:00
Amir-61 954c0df0c6 Merge pull request #1035 from strongloop/globalization_fixup
Fixup globalization
2016-08-09 10:44:06 -04:00
jannyHou 8935b978f3 forceId=true with auto-increment db 2016-08-08 16:26:26 -04:00
Amir Jafarian d181fd0671 Fixup globalization 2016-08-08 15:34:41 -04:00
Miroslav Bajtoš f15b4e2c86 Implement KeyValue API and memory connector
Models attached to a KeyValue connector get the following *static*
methods:

    Color.set(key, value);
    Color.set(key, value, ttl);
    Color.set(key, value, { ttl: ttl });

    Color.get(key);

    Color.expire(key, ttl);
2016-08-08 10:15:34 +02:00
Amir Jafarian 4ce5b5d3a0 Support for globalization 2016-07-28 15:20:18 -04:00
gunjpan 8076be2db1 Remove DataSource.registerType()
Result of compat flag cleanup.
- Current implementation has a wrapper
DataSource.registerType() for
ModelBuilder.registerType(). This removes
the wrapper to encourage use of original
method
2016-06-28 14:45:42 -04:00
Ritchie Martori 293a22fd31 Update datasource.js
Return a real `Error` message for the default `ping()` method.
2016-06-02 14:02:06 -07:00
Raymond Feng daaf5e381a Merge branch 'discover-hang' of https://github.com/TorchlightSoftware/loopback-datasource-juggler into TorchlightSoftware-discover-hang
# Conflicts:
#	lib/datasource.js
#	test/discovery.test.js
2016-04-05 16:18:25 -07:00
Miroslav Bajtoš 27c6279d6c fix remaining eslint issues 2016-04-05 15:25:34 +02:00
Miroslav Bajtoš 39e04a1756 eslint --fix 2016-04-05 15:25:34 +02:00
Ryan Graham c467b43c38 Insert copyright headers 2016-04-04 18:14:03 -07:00
bitmage 57afba8c51 support custom field settings under the connector's namespace 2016-03-16 09:17:55 -07:00
gunjpan 6db59cba6f Update error message for missing connector 2016-03-15 17:01:37 -04:00
Miroslav Bajtoš 9dcf30efe9 Improve error message on connector init error 2016-02-26 14:00:24 +01:00
Candy 686ce5bae3 Fix missing connector error msg for db2, cloudant 2016-02-09 16:19:57 -05:00
bitmage b556d96148 discoverSchemas returns an error when modelName is not found,
discoverSchema forwards that error and does not hang when no columns,
no errors are returned
2016-01-22 10:41:06 -07:00
Raymond Feng 486c1de1ba Merge pull request #715 from nennad/master
foreignKey dataLength fix
2015-11-26 09:28:08 -08:00
nennad e679deb376 typo fix 2015-09-03 17:02:21 +01:00
nennad f3b0cb062e Fix foreignKey length issue
If the PK has a definition like
```
      "mysql": {
        "dataType": "CHAR",
        "dataLength":36,
        "nullable":"N"
      }
```

dataLength is ignored when the PK is used as a foreignKey in other models
2015-09-03 17:00:38 +01:00
sklyukin 483cd873e7 primaryKey to hasOne relation 2015-09-01 01:31:28 +05:00
Raymond Feng 21c0067462 Report deferred exceptions via callback 2015-08-05 11:18:38 -07:00
Pradnya Baviskar c63f3fb6cb Promisify all 'discover' methods 2015-07-24 12:07:22 +05:30
Raymond Feng 6eb18cb2f6 Make sure base property definitions are cloned
Sub models sometimes need to customize the properties from the base model.
This change allows each sub model has its own copy of the base property
definition to avoid potential conflicts across multiple sub models of the
same base.
2015-07-10 10:03:51 -07:00
Pradnya Baviskar e7430184a9 Promisify 'autoupdate' 2015-06-23 18:02:08 +05:30
Pradnya Baviskar f4f13a6626 Promisify 'automigrate' 2015-06-16 12:58:21 +05:30
Raymond Feng 506223885d Mix in observer apis to the connector 2015-05-20 15:02:44 -07:00
crandmck d19001a56e Updated JSdoc for Datasource constructor 2015-05-14 15:53:34 -07:00