ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ivasilin...@apache.org
Subject incubator-ignite git commit: #ignite-961-promise: change nodejs examples.
Date Tue, 14 Jul 2015 14:34:13 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-961-promise e91e38aad -> a501ff8f7


#ignite-961-promise:  change nodejs examples.


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

Branch: refs/heads/ignite-961-promise
Commit: a501ff8f74c0c68b3a5593b46c32aa50944c4dfc
Parents: e91e38a
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Tue Jul 14 17:34:08 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Tue Jul 14 17:34:08 2015 +0300

----------------------------------------------------------------------
 .../main/js/cache-sql-fields-query-example.js   |  9 ++++---
 modules/nodejs/src/main/js/cache.js             | 25 ++++++++++++++++++--
 2 files changed, 27 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a501ff8f/examples/src/main/js/cache-sql-fields-query-example.js
----------------------------------------------------------------------
diff --git a/examples/src/main/js/cache-sql-fields-query-example.js b/examples/src/main/js/cache-sql-fields-query-example.js
index 936dd4a..7290581 100644
--- a/examples/src/main/js/cache-sql-fields-query-example.js
+++ b/examples/src/main/js/cache-sql-fields-query-example.js
@@ -65,14 +65,13 @@ main = function() {
             //Set salary range.
             qry.setArguments([0, 2000]);
 
-            function onQuery(fullRes) {
+            // Run query.
+            ignite.cache(cacheName).query(qry).getAll(function(fullRes){
                 console.log(">>> Names of all employees: " + JSON.stringify(fullRes));
 
+                // Destroying cache on the end of the example.
                 return ignite.destroyCache(cacheName);
-            }
-
-            // Run query.
-            ignite.cache(cacheName).query(qry).getAll(onQuery).then(function(){
+            }).then(function(){
                 console.log(">>> End of sql fields query example.");
             });
         });

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a501ff8f/modules/nodejs/src/main/js/cache.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/cache.js b/modules/nodejs/src/main/js/cache.js
index 3850cb5..6adc592 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -266,6 +266,7 @@ Cache.prototype.size = function(callback) {
  * Execute sql query
  *
  * @param {SqlQuery|SqlFieldsQuery} qry Query
+ * @returns {Cursor} Cursor for current query.
  */
 Cache.prototype.query = function(qry) {
     return new Cursor(this, qry, true, null);
@@ -292,13 +293,34 @@ Cache.prototype._createCommand = function(name) {
     return command.addParam("cacheName", this._cacheName);
 }
 
-Cursor = function(cache, qry, first, res) {
+/**
+ * Creates an instance of Cursor
+ *
+ * @constructor
+ * @this {Cursor}
+ * @param {Cache} cache Cache that runs query
+ * @param {SqlQuery|SqlFieldsQuery} qry Sql query
+ * @param {boolean} init True if query is not started
+ * @param {Object[]} res Current page result
+ */
+Cursor = function(cache, qry, init, res) {
     this._qry = qry;
     this._cache = cache;
     this._init = first;
     this._res = res;
 }
 
+/**
+ * Gets all query results and stores them in the collection.
+ * Use this method when you know in advance that query result is
+ * relatively small and will not cause memory utilization issues.
+ * <p>
+ * Since all the results will be fetched, all the resources will be closed
+ * automatically after this call, e.g. there is no need to call close() method in this case.
+ *
+ * @this{Cursor}
+ * @returns {Promise} Promise with query result
+ */
 Cursor.prototype.getAll = function() {
     if (!this._init) {
         return new Promise(function(resolve, reject){
@@ -335,7 +357,6 @@ Cursor.prototype.getAll = function() {
     });
 }
 
-
 Cursor.prototype.nextPage = function() {
     if (this._res !== null && this._res["last"]) {
         throw "All pages are returned.";


Mime
View raw message