readme examples

Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a561668b
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a561668b
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a561668b

Branch: refs/heads/ignite-7777
Commit: a561668bb651ff52b25399880030bd9bc406ea39
Parents: 19ca55a
Author: ekaterina-nbl <[email protected]>
Authored: Thu May 10 19:01:12 2018 +0300
Committer: ekaterina-nbl <[email protected]>
Committed: Thu May 10 19:01:12 2018 +0300

----------------------------------------------------------------------
 modules/platforms/nodejs/README.md | 74 +++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a561668b/modules/platforms/nodejs/README.md
----------------------------------------------------------------------
diff --git a/modules/platforms/nodejs/README.md 
b/modules/platforms/nodejs/README.md
index 7bf8f92..269fc01 100644
--- a/modules/platforms/nodejs/README.md
+++ b/modules/platforms/nodejs/README.md
@@ -319,6 +319,8 @@ Now, everything is ready to manipulate with the data in the 
cache.
 
 The *CacheClient* class provides methods to manipulate with the key and the 
value of the cache using Key-Value Queries operations - put, get, put all, get 
all, replace, clear, etc.
 
+Example: different cache Key-Value operations with primitive types
+
 ```javascript
 const IgniteClient = require('apache-ignite-client');
 const IgniteClientConfiguration = IgniteClient.IgniteClientConfiguration;
@@ -353,6 +355,72 @@ async function performCacheKeyValueOperations() {
 performCacheKeyValueOperations();
 ```
 
+Example: cache put/get Complex Objects and Binary Objects
+
+```javascript
+const IgniteClient = require('apache-ignite-client');
+const IgniteClientConfiguration = IgniteClient.IgniteClientConfiguration;
+const ObjectType = IgniteClient.ObjectType;
+const CacheEntry = IgniteClient.CacheEntry;
+const ComplexObjectType = IgniteClient.ComplexObjectType;
+
+class Person {
+    constructor(id = null, name = null, salary = null) {
+        this.id = id;
+        this.name = name;
+        this.salary = salary;
+    }
+}
+
+async function putGetComplexAndBinaryObjects() {
+    const igniteClient = new IgniteClient();
+    try {
+        await igniteClient.connect(new 
IgniteClientConfiguration('127.0.0.1:10800'));
+        const cache = await igniteClient.getOrCreateCache('myPersonCache');
+        // Complex Object type for JavaScript Person class instances
+        const personComplexObjectType = new ComplexObjectType(new Person(0, 
'', 0)).
+            setFieldType('id', ObjectType.PRIMITIVE_TYPE.INTEGER); 
+        // set cache key and value types
+        cache.setKeyType(ObjectType.PRIMITIVE_TYPE.INTEGER).
+            setValueType(personComplexObjectType);
+        // put Complex Objects to the cache
+        await cache.put(1, new Person(1, 'John Doe', 1000));
+        await cache.put(2, new Person(2, 'Jane Roe', 2000));
+        // get Complex Object, returned value is an instance of Person class
+        const person = await cache.get(1);
+        console.log(person);
+
+        // set the cache value type to null to operate with BinaryObjects
+        cache.setValueType(null);
+        // get Complex Object from the cache in a binary form, returned value 
is an instance of BinaryObject class
+        let binaryPerson = await cache.get(2);
+        console.log('Binary form of Person:');       
+        for (let fieldName of binaryPerson.getFieldNames()) {
+            let fieldValue = await binaryPerson.getField(fieldName);
+            console.log(fieldName + ' : ' + fieldValue);
+        }
+        // modify Binary Object and put it to the cache
+        binaryPerson.setField('id', 3, ObjectType.PRIMITIVE_TYPE.INTEGER);
+        binaryPerson.setField('name', 'Mary Major');
+        await cache.put(3, binaryPerson);
+
+        // get Binary Object from the cache and convert it to JavaScript Object
+        binaryPerson = await cache.get(3);
+        console.log(await binaryPerson.toObject(personComplexObjectType));
+
+        await igniteClient.destroyCache('myPersonCache');
+    }
+    catch (err) {
+        console.log(err.message);
+    }
+    finally {
+        igniteClient.disconnect();
+    }
+}
+
+putGetComplexAndBinaryObjects();
+```
+
 ### SQL, SQL Fields and Scan Queries ###
 
 The *CacheClient* class provides the query method that accepts an instance of 
a concrete query definition class and returns an instance of a concrete cursor 
class which can be used to obtain the results of the query.
@@ -538,3 +606,9 @@ performSqlFieldsQuery();
 
 To switch on/off the client's debug output (including errors logging), call 
*setDebug()* method of the *IgniteClient* instance. Debug output is disabled by 
default.
 
+```javascript
+const IgniteClient = require('apache-ignite-client');
+
+const igniteClient = new IgniteClient();
+igniteClient.setDebug(true);
+```

Reply via email to