Skip to content
This repository
Browse code

minor fixes and logging

  • Loading branch information...
commit c744bb773c73677dae1eb5553eb5eb7078581881 1 parent 5c1f91e
Francesco authored November 02, 2011
8  Readme.md
Source Rendered
@@ -84,9 +84,9 @@ and monitor the console when you create/modify/delete files on your home directo
84 84
 
85 85
 Dbmon is designed to be dynamic and easily extensible; there are 3 main actors to extend it
86 86
 
87  
-  - **transports**, in [lib/providers](https://github.com/straps/node-dbmon/tree/master/lib/transports) are the way dbmon notify events. You can use how many tranports you want separating them by comma. The name specified in the options object have to match the name of the file followed by `-tranport.js` in the `transports` foler, like the `console` transport in the example above.
  87
+  - **transports**, in [lib/transports](https://github.com/straps/node-dbmon/tree/master/lib/transports) are the way dbmon notify events. You can use how many tranports you want separating them by comma. The name specified in the options object have to match the name of the file followed by `-tranport.js` in the `transports` foler, like the `console` transport in the example above.
88 88
   - **providers**, in [lib/providers](https://github.com/straps/node-dbmon/tree/master/lib/providers), have to initialize their method to fetch data and notify transports whene something happen; in most cases (surely for postgresql case) they should only require the `generic-driver` that dynamiccaly instantiate the method and notify transports
89  
-  - **methods**, in [lib/providers](https://github.com/straps/node-dbmon/tree/master/lib/methods), are the core of the system; their implementation depends upon the driver and the method specified in the configuration object and their name should respect `DRIVER-METHOD-method.js` convention (ie: postgresql-trigger-method.js). Methods init function return an `EventEmitter` inherited object that notify listeners where data changes firing the event notification chain
  89
+  - **methods**, in [lib/methods](https://github.com/straps/node-dbmon/tree/master/lib/methods), are the core of the system; their implementation depends upon the driver and the method specified in the configuration object and their name should respect `DRIVER-METHOD-method.js` convention (ie: postgresql-trigger-method.js). Methods init function return an `EventEmitter` inherited object that notify listeners where data changes firing the event notification chain
90 90
 
91 91
 
92 92
 ### How To Create a new Transport
@@ -187,8 +187,8 @@ Only for test
187 187
 
188 188
 ## ToDo
189 189
   - Develop other drivers (MySQL, Oracle, MsSQL, etc...)
190  
-  - Develop other transports (Faye, Hook.io, etc..)
191  
-  - Write better tests with a single connection, command line parameters and one file per driver/method/transport
  190
+  - Develop other transports (Hook.io, etc..)
  191
+  - Write better unit tests
192 192
 
193 193
 
194 194
 ## License
3  lib/methods/filesystem-inotifywait-method.js
@@ -7,6 +7,9 @@ var init=function init(opts){
7 7
   var nChanges=0;
8 8
 
9 9
   var inotifywait = spawn('inotifywait', ['-m', '-r', '-q', '--format', '"%e %w%f"', opts.driverOpts[opts.driver].root]);
  10
+
  11
+  console.log('Monitoring '+opts.driverOpts[opts.driver].root+' and subfolders');
  12
+
10 13
   inotifywait.stderr.setEncoding('utf8');
11 14
   inotifywait.stderr.on('data', function (data) {
12 15
     if (/^execvp\(\)/.test(data)) {
47  lib/methods/postgresql-trigger-method.js
@@ -8,26 +8,30 @@ var name=function name(table, type){
8 8
 
9 9
 /** Compose and returns CREATE FUNCTION query */
10 10
 var triggerFnStr=function triggerFnStr(type, opts){
11  
-  var n=name(opts.table, type),
12  
-      historyTable=name(opts.table, 'history')+'_table',
13  
-      shortType=type.charAt(0),
14  
-      rec=type==='delete'?'OLD':'NEW';
15  
-  var rv='CREATE OR REPLACE FUNCTION '+n+'_fn() RETURNS trigger AS $$\n'+
16  
-            'DECLARE\n'+
17  
-            'BEGIN\n'+
18  
-                (opts.keyfld.name && opts.keyfld.type?
19  
-                  'INSERT INTO '+historyTable+' (op, k, oldk)'+
20  
-                    (type==='truncate'?
21  
-                      'VALUES (\''+shortType+'\', NULL, NULL);\n':
22  
-                      //If UPDATE, save also the old key field value
23  
-                      'VALUES (\''+shortType+'\', '+rec+'.'+opts.keyfld.name+', '+(type==='update'?'OLD.'+opts.keyfld.name:rec+'.'+opts.keyfld.name)+');\n'
24  
-                    )
25  
-                :'')+
26  
-              'NOTIFY '+n+';\n'+
27  
-              'RETURN '+rec+';\n'+
28  
-            'END;\n'+
29  
-            '$$ LANGUAGE plpgsql;';
30  
-  return rv;
  11
+  if (opts.table){
  12
+    var n=name(opts.table, type),
  13
+        historyTable=name(opts.table, 'history')+'_table',
  14
+        shortType=type.charAt(0),
  15
+        rec=type==='delete'?'OLD':'NEW';
  16
+    var rv='CREATE OR REPLACE FUNCTION '+n+'_fn() RETURNS trigger AS $$\n'+
  17
+              'DECLARE\n'+
  18
+              'BEGIN\n'+
  19
+                  (opts.keyfld.name && opts.keyfld.type?
  20
+                    'INSERT INTO '+historyTable+' (op, k, oldk)'+
  21
+                      (type==='truncate'?
  22
+                        'VALUES (\''+shortType+'\', NULL, NULL);\n':
  23
+                        //If UPDATE, save also the old key field value
  24
+                        'VALUES (\''+shortType+'\', '+rec+'.'+opts.keyfld.name+', '+(type==='update'?'OLD.'+opts.keyfld.name:rec+'.'+opts.keyfld.name)+');\n'
  25
+                      )
  26
+                  :'')+
  27
+                'NOTIFY '+n+';\n'+
  28
+                'RETURN '+rec+';\n'+
  29
+              'END;\n'+
  30
+              '$$ LANGUAGE plpgsql;';
  31
+    return rv;
  32
+  }else{
  33
+    console.log('postgresql-trigger-method.js, opts.table REQUIRED');
  34
+  }
31 35
 };
32 36
 /** Compose and returns CREATE TRIGGER query */
33 37
 var triggerStr=function triggerStr(type, opts){
@@ -87,6 +91,7 @@ var init=function init(opts){
87 91
       if (opts.keyfld.name && opts.keyfld.type){
88 92
         cli.query(historyTableStr(opts), this);
89 93
       }else{
  94
+        console.log('postgresql-trigger-method.js, history table not created, opts.keyfld or opts.keytype not valid');
90 95
         this();
91 96
       }
92 97
     },
@@ -117,4 +122,4 @@ var init=function init(opts){
117 122
   return me;
118 123
 };
119 124
 
120  
-module.exports={init:init};
  125
+module.exports={init:init};
6  lib/transports/faye-transport.js
... ...
@@ -1,7 +1,7 @@
1 1
 //Faye Tranport
2 2
 var faye = require('faye'), bayeux;
3 3
 var init=function init(opts){
4  
-  console.log('Faye Transport init');
  4
+  console.log('Faye Transport init, mount='+opts.transportsOpts.faye.mount+', channel='+opts.transportsOpts.faye.channel);
5 5
 
6 6
   bayeux = new faye.NodeAdapter({mount: opts.transportsOpts.faye.mount, timeout: opts.transportsOpts.faye.timeout});
7 7
   if (opts.transportsOpts.faye.server){
@@ -10,7 +10,7 @@ var init=function init(opts){
10 10
     bayeux.listen(opts.transportsOpts.faye.port);
11 11
   }
12 12
 
13  
-  var rxType=/_TYPE_/g; //compiles only one time
  13
+  var rxType=/_TYPE_/g; //compiled only the first time
14 14
   var me={
15 15
     notify:function(type, row){
16 16
       var channel=opts.transportsOpts.faye.channel.replace(rxType, type);
@@ -26,4 +26,4 @@ var init=function init(opts){
26 26
 
27 27
 };
28 28
 
29  
-module.exports={init:init};
  29
+module.exports={init:init};

0 notes on commit c744bb7

Please sign in to comment.
Something went wrong with that request. Please try again.