Changeset: 6959733f769d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6959733f769d
Modified Files:
        clients/nodejs/Tests/nodetest.js
        clients/nodejs/monetdb/README.md
        clients/nodejs/monetdb/mapiclient.js
        clients/nodejs/monetdb/package.json
Branch: default
Log Message:

Merge with default


diffs (94 lines):

diff --git a/clients/nodejs/Tests/nodetest.js b/clients/nodejs/Tests/nodetest.js
--- a/clients/nodejs/Tests/nodetest.js
+++ b/clients/nodejs/Tests/nodetest.js
@@ -87,8 +87,20 @@ conn.query('SELECT id from tables where 
        ['connections', 0, false], function(err, res) {
                assert.equal(null, err);
                assert(res.rows > 0);
+}); 
 
-}); 
+/* Try the log callback functionality */
+var nr_log_callbacks = 0;
+conn.log_callback = function(message, error, result) {
+       assert(message); // message must contain something
+       ++nr_log_callbacks;
+}
+conn.query('SELECT id FROM tables WHERE name=? AND type=? AND readonly=?',
+       ['connections', 0, false], function(err, res) {
+               assert.equal(null, err);
+               assert(nr_log_callbacks > 0);
+               conn.log_callback = null;       
+});
 
 /* some quoting fun, jesus */
 conn.query("SELECT '\\\\asdf','\"', '\\\"', '\\\\\"', '\\''", function(err, 
res) {
diff --git a/clients/nodejs/monetdb/README.md b/clients/nodejs/monetdb/README.md
--- a/clients/nodejs/monetdb/README.md
+++ b/clients/nodejs/monetdb/README.md
@@ -93,6 +93,14 @@ Empty the query queue and then close the
 
 
 
+# <a name="log"></a>Query logging
+Every time a query result is returned from the database, the callback function 
*conn.log_callback*, which defaults to null, will be executed right before the 
query callback function is executed (conn refers to a connection object 
returned by the [connect function](#connect)). If you have some general 
behavior that you want to be executed every time a query finishes, you can set 
*conn.log_callback* to a function with the following signature:
+
+function(query, err, res)
+- query: the SQL query that lead to this result (note: if you pass a params 
array to the [query function](#query), multiple queries are fired to the 
database, hence the log callback will be called multiple times)
+- err, res: Same as in the callback for the [query function](#query)
+
+
 # <a name="q"></a>Q Integration
 Due to the huge popularity of the [Q module for 
NodeJS](https://www.npmjs.org/package/q), we decided to add native Q support, 
that wraps our API in a promise returning API that exists on top of the 
original API, so you can use both interchangeably. 
 
diff --git a/clients/nodejs/monetdb/mapiclient.js 
b/clients/nodejs/monetdb/mapiclient.js
--- a/clients/nodejs/monetdb/mapiclient.js
+++ b/clients/nodejs/monetdb/mapiclient.js
@@ -8,7 +8,7 @@ function MonetDBConnection(options, conn
        this.read_leftover = 0;
        this.read_final = false;
        this.read_str = '';
-       this.read_callback = undefined;
+       this.cur_op = undefined; // object { message (str), callback (fn)}
        this.conn_callback = conncallback;
        this.mapi_blocksize = 8192;
        this.do_close = false;
@@ -223,11 +223,14 @@ function handle_message(message) {
        if (message.charAt(0) == '&') {
                response = _parseresponse(message);
        }
-
-       if (this.read_callback != undefined) {
-               this.read_callback(error, response);
-               this.read_callback = undefined;
+       if(typeof(this.log_callback) == "function") {
+               this.log_callback(this.cur_op.message, error, response);
        }
+       if (this.cur_op.callback != undefined) {
+               this.cur_op.callback(error, response);
+               this.cur_op.callback = undefined;
+       }
+       this.cur_op.message = undefined;
        next_op.call(this);
 }
 
@@ -243,7 +246,7 @@ function next_op() {
 
        var op = this.queryqueue.shift();
        send_message.call(this, op.message);
-       this.read_callback = op.callback;
+       this.cur_op = op;
 }
 
 function cleanup() {
diff --git a/clients/nodejs/monetdb/package.json 
b/clients/nodejs/monetdb/package.json
--- a/clients/nodejs/monetdb/package.json
+++ b/clients/nodejs/monetdb/package.json
@@ -1,6 +1,6 @@
 {
   "name": "monetdb",
-  "version": "0.2.2",
+  "version": "0.2.3",
   "description": "Connect MonetDB and node.js",
   "main": "mapiclient.js",
   "author": "Hannes Mühleisen <han...@cwi.nl>",
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to