-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.js
797 lines (682 loc) · 31.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
/**
* Module Dependencies
*/
var async = require('async'),
_ = require('lodash'),
db2 = require('ibm_db'),
WaterlineAdapterErrors = require('waterline-errors').adapter;
/**
* Sails Boilerplate Adapter
*
* Most of the methods below are optional.
*
* If you don't need / can't get to every method, just implement
* what you have time for. The other methods will only fail if
* you try to call them!
*
* For many adapters, this file is all you need. For very complex adapters, you may need more flexiblity.
* In any case, it's probably a good idea to start with one file and refactor only if necessary.
* If you do go that route, it's conventional in Node to create a `./lib` directory for your private submodules
* and load them at the top of the file with other dependencies. e.g. var update = `require('./lib/update')`;
*/
module.exports = (function () {
var me = this;
// You'll want to maintain a reference to each collection
// (aka model) that gets registered with this adapter.
me.connections = {};
// You may also want to store additional, private data
// per-collection (esp. if your data store uses persistent
// connections).
//
// Keep in mind that models can be configured to use different databases
// within the same app, at the same time.
//
// i.e. if you're writing a MariaDB adapter, you should be aware that one
// model might be configured as `host="localhost"` and another might be using
// `host="foo.com"` at the same time. Same thing goes for user, database,
// password, or any other config.
//
// You don't have to support this feature right off the bat in your
// adapter, but it ought to get done eventually.
//
// Sounds annoying to deal with...
// ...but it's not bad. In each method, acquire a connection using the config
// for the current model (looking it up from `_modelReferences`), establish
// a connection, then tear it down before calling your method's callback.
// Finally, as an optimization, you might use a db pool for each distinct
// connection configuration, partioning pools for each separate configuration
// for your adapter (i.e. worst case scenario is a pool for each model, best case
// scenario is one single single pool.) For many databases, any change to
// host OR database OR user OR password = separate pool.
me.dbPools = {};
me.getConnectionString = function (connection) {
var connectionData = [
'DRIVER={DB2}',
'DATABASE=' + connection.config.database,
'HOSTNAME=' + connection.config.host,
'UID=' + connection.config.user,
'PWD=' + connection.config.password,
'PORT=' + connection.config.port,
'PROTOCOL=TCPIP'
];
return connectionData.join(';');
};
me.escape = function (word) {
return "'" + word.replace("'", "''") + "'";
};
// Data types
// Waterline source: https://www.npmjs.org/package/waterline#attributes
// IBM DB2 source: http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2z9.doc.sqlref%2Fsrc%2Ftpc%2Fdb2z_datatypesintro.htm
me.typeMap = {
// Times
TIMESTMP: 'time',
TIME: 'time',
DATE: 'date',
// Binaries
BINARY: 'binary',
VARBINARY: 'binary',
// Strings
CHAR: 'string',
VARCHAR: 'string',
GRAPHIC: 'string',
VARGRAPHIC: 'string',
// Integers
SMALLINT: 'integer',
INTEGER: 'integer',
BIGINT: 'integer',
// Floats
DECIMAL: 'float',
DECFLOAT: 'float',
REAL: 'float',
DOUBLE: 'float',
// Texts
CLOB: 'text',
BLOB: 'text',
DBCLOB: 'text',
XML: 'text'
};
me.getSqlType = function (attrType) {
var type = '';
switch (attrType) {
case 'string':
type = 'VARCHAR';
break;
case 'integer':
type = 'INTEGER';
break;
case 'float':
type = 'DOUBLE';
break;
case 'text':
type = 'BLOB';
break;
case 'binary':
type = 'VARBINARY';
break;
case 'time':
type = 'TIMESTMP';
break;
case 'date':
type = 'DATE';
break;
}
return type;
};
me.getSelectAttributes = function (collection) {
return _.keys(collection.definition).join(',');
};
me.closeConnection = function (connection) {
connection.close(function (err) {
if (err) logger.error(err);
});
};
me.getTableName = function (tableName, schema) {
var result = tableName;
if (typeof schema === 'string' && schema.length > 0) result = ' ' + schema + '.' + tableName + ' ';
return result;
};
var adapter = {
identity: 'sails-db2',
// Set to true if this adapter supports (or requires) things like data types, validations, keys, etc.
// If true, the schema for models using this adapter will be automatically synced when the server starts.
// Not terribly relevant if your data store is not SQL/schemaful.
syncable: true,
// Default configuration for collections
// (same effect as if these properties were included at the top level of the model definitions)
defaults: {
host: 'localhost',
port: 50000,
schema: true,
ssl: false,
// If setting syncable, you should consider the migrate option,
// which allows you to set how the sync will be performed.
// It can be overridden globally in an app (config/adapters.js)
// and on a per-model basis.
//
// IMPORTANT:
// `migrate` is not a production data migration solution!
// In production, always use `migrate: safe`
//
// drop => Drop schema and data, then recreate it
// alter => Drop/add columns as necessary.
// safe => Don't change anything (good for production DBs)
migrate: 'alter'
},
/**
*
* This method runs when a model is initially registered
* at server-start-time. This is the only required method.
*
* @param {[type]} collection [description]
* @param {Function} cb [description]
* @return {[type]} [description]
*/
registerConnection: function (connection, collections, cb) {
// Validate arguments
if (!connection.identity) return cb(WaterlineAdapterErrors.IdentityMissing);
if (me.connections[connection.identity]) return cb(WaterlineAdapterErrors.IdentityDuplicate);
var host = connection.host;
if (host && typeof host === 'string' && host.search(':') !== -1) connection.host = host.split(':')[0];
connection.schemaDB2 = connection.schemaDB2 || connection.user;
me.connections[connection.identity] = {
config: connection,
collections: collections,
pool: connection.pool ? new db2.Pool() : null,
conn: null
};
return cb();
},
/**
* Fired when a model is unregistered, typically when the server
* is killed. Useful for tearing-down remaining open connections,
* etc.
*
* @param {Function} cb [description]
* @return {[type]} [description]
*/
teardown: function (connectionName, cb) {
var closeConnection = function (connectionName) {
var connection = me.connections[connectionName];
if (connection) {
if (connection.conn && typeof connection.conn.close === 'function') {
connection.conn.close(function (err) {
if (err) console.error(err);
});
}
else {
connection.close(function (err) {
if (err) console.error(err);
});
}
}
delete me.connections[connectionName];
};
if (connectionName) closeConnection(connectionName);
else _.each(me.connections, closeConnection);
return cb();
},
/**
*
* REQUIRED method if integrating with a schemaful
* (SQL-ish) database.
*
* @param {[type]} collectionName [description]
* @param {[type]} definition [description]
* @param {Function} cb [description]
* @return {[type]} [description]
*/
define: function (connectionName, collectionName, definition, cb) {
var connection = me.connections[connectionName],
collection = connection.collections[collectionName],
query = 'CREATE TABLE ' + collectionName,
schemaData = [],
schemaQuery = '';
_.each(definition, function (attribute, attrName) {
var attrType = me.getSqlType(attribute.type),
attrQuery = attrName;
// @todo: handle unique and other DB2 data types
if (attribute.primaryKey) {
if (attribute.autoIncrement) attrQuery += ' INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY';
else attrQuery += ' VARCHAR(255) NOT NULL PRIMARY KEY';
}
else {
switch (attrType) {
case 'VARCHAR':
var len = attribute.length || 255;
attrQuery += ' ' + attrType + '(' + len + ')';
break;
// @todo: handle each type with correct params
case 'DOUBLE':
case 'BLOB':
case 'VARBINARY':
case 'TIMESTMP':
case 'DATE':
case 'INTEGER':
default:
attrQuery += ' ' + attrType;
}
}
schemaData.push(attrQuery);
});
schemaQuery += '(' + schemaData.join(',') + ')';
query += ' ' + schemaQuery;
// @todo: use DB2 Database describe method instead of a SQL Query
return adapter.query(connectionName, collectionName, query, function (err, result) {
if (err) {
if (err.state !== '42S01') return cb(err);
result = [];
}
return cb(null, result);
});
},
/**
*
* REQUIRED method if integrating with a schemaful
* (SQL-ish) database.
*
* @param {[type]} collectionName [description]
* @param {Function} cb [description]
* @return {[type]} [description]
*/
describe: function (connectionName, collectionName, cb) {
var connection = me.connections[connectionName],
collection = connection.collections[collectionName],
query = 'SELECT DISTINCT(NAME), COLTYPE, IDENTITY, KEYSEQ, NULLS FROM Sysibm.syscolumns WHERE tbname = ' + me.escape(collectionName);
// @todo: use DB2 Database describe method instead of a SQL Query
adapter.query(connectionName, collectionName, query, function (err, attrs) {
if (err) return cb(err);
if (attrs.length === 0) return cb(null, null);
var attributes = {};
// Loop through Schema and attach extra attributes
// @todo: check out a better solution to define primary keys following db2 docs
attrs.forEach(function (attr) {
var attribute = {
type: me.typeMap[attr.COLTYPE.trim()]
};
if (attr.IDENTITY === 'Y' && attr.KEYSEQ !== 0 && attr.NULLS === 'N' && attribute.type === 'integer') {
attribute.primaryKey = true;
attribute.autoIncrement = true;
attribute.unique = true;
}
attributes[attr.NAME] = attribute;
});
cb(null, attributes);
});
},
/**
*
*
* REQUIRED method if integrating with a schemaful
* (SQL-ish) database.
*
* @param {[type]} collectionName [description]
* @param {[type]} relations [description]
* @param {Function} cb [description]
* @return {[type]} [description]
*/
drop: function (connectionName, collectionName, relations, cb) {
if (_.isFunction(relations)) {
cb = relations;
relations = [];
}
var connection = me.connections[connectionName],
connectionString = me.getConnectionString(connection),
__DROP__ = function () {
// Drop any relations
var dropTable = function (tableName, next) {
// Build query
var query = 'DROP TABLE ' + me.getTableName(tableName, connection.config.schemaDB2);
// Run query
openConnection.query(query, next);
},
passCallback = function (err, result) {
me.closeConnection(openConnection);
if (err) {
if (err.state !== '42S02') return cb(err);
result = [];
}
cb(null, result);
};
async.eachSeries(relations, dropTable, function (err) {
if (err) return cb(err);
return dropTable(collectionName, passCallback);
});
openConnection.query('DROP TABLE ' + collectionName, relations, passCallback);
},
operationCallback = function (err, conn) {
if (err) return cb(err);
openConnection = conn;
return __DROP__();
},
openConnection;
if (connection.pool) return connection.pool.open(connectionString, operationCallback);
else return db2.open(connectionString, operationCallback);
},
// OVERRIDES NOT CURRENTLY FULLY SUPPORTED FOR:
//
// alter: function (collectionName, changes, cb) {},
// addAttribute: function(collectionName, attrName, attrDef, cb) {},
// removeAttribute: function(collectionName, attrName, attrDef, cb) {},
// alterAttribute: function(collectionName, attrName, attrDef, cb) {},
// addIndex: function(indexName, options, cb) {},
// removeIndex: function(indexName, options, cb) {},
query: function (connectionName, collectionName, query, data, cb) {
if (_.isFunction(data)) {
cb = data;
data = null;
}
var connection = me.connections[connectionName],
connectionString = me.getConnectionString(connection),
__QUERY__ = function () {
var callback = function (err, records) {
me.closeConnection(openConnection);
if (err) return cb(err);
cb(null, records);
};
if (_.isArray(data) && data.length > 0) openConnection.query(query, data, callback);
else openConnection.query(query, callback);
},
operationCallback = function (err, conn) {
if (err) return cb(err);
openConnection = conn;
return __QUERY__();
},
openConnection;
if (connection.pool) return connection.pool.open(connectionString, operationCallback);
else return db2.open(connectionString, operationCallback);
},
/**
*
* REQUIRED method if users expect to call Model.find(), Model.findOne(),
* or related.
*
* You should implement this method to respond with an array of instances.
* Waterline core will take care of supporting all the other different
* find methods/usages.
*
* @param {[type]} collectionName [description]
* @param {[type]} options [description]
* @param {Function} cb [description]
* @return {[type]} [description]
*/
find: function (connectionName, collectionName, options, cb) {
var connection = me.connections[connectionName],
collection = connection.collections[collectionName],
connectionString = me.getConnectionString(connection),
__FIND__ = function () {
var selectQuery = 'SELECT ' + me.getSelectAttributes(collection),
fromQuery = ' FROM ' + me.getTableName(collection.tableName, connection.config.schemaDB2),
whereData = [],
whereQuery = '',
limitQuery = !_.isEmpty(options.limit) ? ' FETCH FIRST ' + options.limit + ' ROWS ONLY ' : '',
sortData = [],
sortQuery = '',
params = [],
sqlQuery = '';
// Building where clause
_.each(options.where, function (param, column) {
if (_.isArray(param)) {
var whereArr = [];
param.forEach(function (val) {
whereArr.push(column + ' = ?');
if (collection.definition[column].type === 'boolean') params.push(val === true ? 1 : 0);
else params.push(val);
});
whereData.push('(' + whereArr.join(' OR ') + ')');
}
else {
if (collection.definition.hasOwnProperty(column)) {
whereData.push(column + ' = ?');
if (collection.definition[column].type === 'boolean') params.push(param === true ? 1 : 0);
else params.push(param);
}
}
});
whereQuery += whereData.join(' AND ');
if (whereQuery.length > 0) whereQuery = ' WHERE ' + whereQuery;
// Building sort clause
_.each(options.sort, function (direction, column) {
if (collection.definition.hasOwnProperty(column)) {
//ORDER BY APPLICATIONCODE DESC
sortData.push(column + ' ' + direction);
}
});
sortQuery += sortData.join(', ');
if (sortQuery.length > 0) sortQuery = ' ORDER BY ' + sortQuery;
sqlQuery += selectQuery + fromQuery + whereQuery + sortQuery + limitQuery;
openConnection.query(sqlQuery, params, function (err, result) {
me.closeConnection(openConnection);
if (err) return cb(err);
cb(null, result);
});
// Options object is normalized for you:
//
// options.where
// options.limit
// options.sort
// Filter, paginate, and sort records from the datastore.
// You should end up w/ an array of objects as a result.
// If no matches were found, this will be an empty array.
},
operationCallback = function (err, conn) {
if (err) return cb(err);
openConnection = conn;
return __FIND__();
},
openConnection;
if (connection.pool) return connection.pool.open(connectionString, operationCallback);
else return db2.open(connectionString, operationCallback);
},
/**
*
* REQUIRED method if users expect to call Model.create() or any methods
*
* @param {[type]} collectionName [description]
* @param {[type]} values [description]
* @param {Function} cb [description]
* @return {[type]} [description]
*/
create: function (connectionName, collectionName, values, cb) {
var connection = me.connections[connectionName],
collection = connection.collections[collectionName],
connectionString = me.getConnectionString(connection),
__CREATE__ = function () {
var selectQuery = me.getSelectAttributes(collection),
columns = [],
params = [],
questions = [];
_.each(values, function (param, column) {
if (collection.definition.hasOwnProperty(column)) {
columns.push(column);
if (collection.definition[column].type === 'boolean') params.push(param === true ? 1 : 0);
else params.push(param);
questions.push('?');
}
});
openConnection.query('SELECT ' + selectQuery + ' FROM FINAL TABLE (INSERT INTO ' + me.getTableName(collection.tableName, connection.config.schemaDB2) + ' (' + columns.join(',') + ') VALUES (' + questions.join(',') + '))', params, function (err, results) {
me.closeConnection(openConnection);
if (err) cb(err);
else cb(null, results[0]);
});
},
operationCallback = function (err, conn) {
if (err) return cb(err);
openConnection = conn;
return __CREATE__();
},
openConnection;
if (connection.pool) return connection.pool.open(connectionString, operationCallback);
else return db2.open(connectionString, operationCallback);
},
/**
*
*
* REQUIRED method if users expect to call Model.update()
*
* @param {[type]} collectionName [description]
* @param {[type]} options [description]
* @param {[type]} values [description]
* @param {Function} cb [description]
* @return {[type]} [description]
*/
update: function (connectionName, collectionName, options, values, cb) {
var connection = me.connections[connectionName],
collection = connection.collections[collectionName],
connectionString = me.getConnectionString(connection),
__UPDATE__ = function () {
var selectQuery = me.getSelectAttributes(collection),
setData = [],
setQuery = '',
whereData = [],
whereQuery = '',
params = [],
sqlQuery = '';
_.each(values, function (param, column) {
if (collection.definition.hasOwnProperty(column) && !collection.definition[column].autoIncrement) {
setData.push(column + ' = ?');
if (collection.definition[column].type === 'boolean') params.push(param === true ? 1 : 0);
else params.push(param);
}
});
setQuery = ' SET ' + setData.join(',');
_.each(options.where, function (param, column) {
if (collection.definition.hasOwnProperty(column)) {
whereData.push(column + ' = ?');
if (collection.definition[column].type === 'boolean') params.push(param === true ? 1 : 0);
else params.push(param);
}
});
whereQuery += whereData.join(' AND ');
if (whereQuery.length > 0) whereQuery = ' WHERE ' + whereQuery;
sqlQuery = 'SELECT ' + selectQuery + ' FROM FINAL TABLE (UPDATE ' + me.getTableName(collection.tableName, connection.config.schemaDB2) + setQuery + whereQuery + ')';
openConnection.query(sqlQuery, params, function (err, results) {
me.closeConnection(openConnection);
if (err) return cb(err);
cb(null, results[0]);
});
},
operationCallback = function (err, conn) {
if (err) return cb(err);
openConnection = conn;
return __UPDATE__();
},
openConnection;
if (connection.pool) return connection.pool.open(connectionString, operationCallback);
else return db2.open(connectionString, operationCallback);
},
/**
*
* REQUIRED method if users expect to call Model.destroy()
*
* @param {[type]} collectionName [description]
* @param {[type]} options [description]
* @param {Function} cb [description]
* @return {[type]} [description]
*/
destroy: function (connectionName, collectionName, options, cb) {
var connection = me.connections[connectionName],
collection = connection.collections[collectionName],
connectionString = me.getConnectionString(connection),
__DESTROY__ = function () {
var whereData = [],
whereQuery = '',
params = [];
_.each(options.where, function (param, column) {
if (collection.definition.hasOwnProperty(column)) {
whereData.push(column + ' = ?');
if (collection.definition[column].type === 'boolean') params.push(param === true ? 1 : 0);
else params.push(param);
}
});
whereQuery += whereData.join(' AND ');
if (whereQuery.length > 0) whereQuery = ' WHERE ' + whereQuery;
openConnection.query('DELETE FROM ' + me.getTableName(collection.tableName, connection.config.schemaDB2) + whereQuery, params, function (err, result) {
me.closeConnection(openConnection);
if (err) return cb(err);
cb(null, result);
});
},
operationCallback = function (err, conn) {
if (err) return cb(err);
openConnection = conn;
return __DESTROY__();
},
openConnection;
if (connection.pool) return connection.pool.open(connectionString, operationCallback);
else return db2.open(connectionString, operationCallback);
}
/*
**********************************************
* Optional overrides
**********************************************
// Optional override of built-in batch create logic for increased efficiency
// (since most databases include optimizations for pooled queries, at least intra-connection)
// otherwise, Waterline core uses create()
createEach: function (collectionName, arrayOfObjects, cb) { cb(); },
// Optional override of built-in findOrCreate logic for increased efficiency
// (since most databases include optimizations for pooled queries, at least intra-connection)
// otherwise, uses find() and create()
findOrCreate: function (collectionName, arrayOfAttributeNamesWeCareAbout, newAttributesObj, cb) { cb(); },
*/
/*
**********************************************
* Custom methods
**********************************************
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// > NOTE: There are a few gotchas here you should be aware of.
//
// + The collectionName argument is always prepended as the first argument.
// This is so you can know which model is requesting the adapter.
//
// + All adapter functions are asynchronous, even the completely custom ones,
// and they must always include a callback as the final argument.
// The first argument of callbacks is always an error object.
// For core CRUD methods, Waterline will add support for .done()/promise usage.
//
// + The function signature for all CUSTOM adapter methods below must be:
// `function (collectionName, options, cb) { ... }`
//
////////////////////////////////////////////////////////////////////////////////////////////////////
// Custom methods defined here will be available on all models
// which are hooked up to this adapter:
//
// e.g.:
//
foo: function (collectionName, options, cb) {
return cb(null,"ok");
},
bar: function (collectionName, options, cb) {
if (!options.jello) return cb("Failure!");
else return cb();
}
// So if you have three models:
// Tiger, Sparrow, and User
// 2 of which (Tiger and Sparrow) implement this custom adapter,
// then you'll be able to access:
//
// Tiger.foo(...)
// Tiger.bar(...)
// Sparrow.foo(...)
// Sparrow.bar(...)
// Example success usage:
//
// (notice how the first argument goes away:)
Tiger.foo({}, function (err, result) {
if (err) return console.error(err);
else console.log(result);
// outputs: ok
});
// Example error usage:
//
// (notice how the first argument goes away:)
Sparrow.bar({test: 'yes'}, function (err, result){
if (err) console.error(err);
else console.log(result);
// outputs: Failure!
})
*/
};
// Expose adapter definition
return adapter;
})();