|
1 | 1 | # RavenDB client for Node.js
|
2 | 2 |
|
| 3 | +[](https://nodei.co/npm/ravendb/) |
| 4 | + |
3 | 5 | [](https://travis-ci.org/ravendb/ravendb-nodejs-client) [](https://snyk.io/test/github/ravendb/ravendb-nodejs-client)
|
4 | 6 |
|
5 | 7 | ## Changelog
|
6 | 8 |
|
| 9 | +### 4.0.4 - 2018-10-18 |
| 10 | +- added support for [Subscriptions](#subscriptions) |
| 11 | +- added support for storing timezone info and dates in UTC |
| 12 | +- enhanced load and bulk insert performance |
| 13 | +- other bug fixes |
| 14 | + |
7 | 15 | ### 4.0.3 - 2018-10-01
|
8 | 16 | Added support for the following features:
|
9 | 17 | - [Streaming](#streaming)
|
@@ -747,14 +755,67 @@ session.advanced.patch("users/1", "underAge", false);
|
747 | 755 |
|
748 | 756 | await session.saveChanges();
|
749 | 757 | ```
|
| 758 | +### Subscriptions |
| 759 | +```javascript |
| 760 | +// create a subscription |
| 761 | +const subscriptionName = await store.subscriptions.create({ |
| 762 | + query: "from users where age >= 30" |
| 763 | +}); |
| 764 | + |
| 765 | +// get subscription worker for your subscription |
| 766 | +const subscription = store.subscriptions.getSubscriptionWorker({ subscriptionName }); |
| 767 | + |
| 768 | +subscription.on("error", err => { |
| 769 | + // handle errors |
| 770 | +}); |
| 771 | + |
| 772 | +subscription.on("batch", (batch, callback) => { |
| 773 | + try { |
| 774 | + // do batch processing on batch.items |
| 775 | + // batch.items: |
| 776 | + // [ Item { |
| 777 | + // changeVector: 'A:2-r6nkF5nZtUKhcPEk6/LL+Q', |
| 778 | + // id: 'users/1-A', |
| 779 | + // rawResult: |
| 780 | + // { name: 'John', |
| 781 | + // age: 30, |
| 782 | + // registeredAt: '2017-11-11T00:00:00.0000000', |
| 783 | + // kids: [Array], |
| 784 | + // '@metadata': [Object], |
| 785 | + // id: 'users/1-A' }, |
| 786 | + // rawMetadata: |
| 787 | + // { '@collection': 'Users', |
| 788 | + // '@nested-object-types': [Object], |
| 789 | + // 'Raven-Node-Type': 'User', |
| 790 | + // '@change-vector': 'A:2-r6nkF5nZtUKhcPEk6/LL+Q', |
| 791 | + // '@id': 'users/1-A', |
| 792 | + // '@last-modified': '2018-10-18T11:15:51.4882011Z' }, |
| 793 | + // exceptionMessage: undefined } ] |
| 794 | + // ... |
| 795 | + |
| 796 | + // call the callback, once you're done |
| 797 | + callback(); |
| 798 | + } catch(err) { |
| 799 | + // if processing fails for a particular batch |
| 800 | + // pass the error to the callback |
| 801 | + callback(err); |
| 802 | + } |
| 803 | +}); |
| 804 | +``` |
750 | 805 |
|
751 | 806 | ## Using object literals for entities
|
752 | 807 |
|
753 |
| -In order to comfortably use object literals as entities set function getting collection name based on the content of the object - `store.conventions.findCollectionNameForObjectLiteral()`. This needs to be done *before* an `initialize()` call on `DocumentStore` instance. If you fail to do so, your entites will land up in *@empty* collection having an *UUID* for an ID. E.g. |
| 808 | +In order to comfortably use object literals as entities set the function getting collection name based on the content of the object - `store.conventions.findCollectionNameForObjectLiteral()`. |
| 809 | + |
754 | 810 | ```javascript
|
| 811 | +const store = new DocumentStore(urls, database); |
755 | 812 | store.conventions.findCollectionNameForObjectLiteral = entity => entity["collection"];
|
| 813 | +// ... |
| 814 | +store.initialize(); |
756 | 815 | ```
|
757 | 816 |
|
| 817 | +This needs to be done *before* an `initialize()` call on `DocumentStore` instance. If you fail to do so, your entites will land up in *@empty* collection having an *UUID* for an ID. E.g. |
| 818 | + |
758 | 819 | ## Using classes for entities
|
759 | 820 |
|
760 | 821 | 1. Define your model as class. Attributes should be just public properties:
|
|
0 commit comments