@@ -115,26 +115,33 @@ adapter.defaults = {
115
115
* @param {Function } cb [description]
116
116
* @return {[type] } [description]
117
117
*/
118
- adapter . registerConnection = function registerConnection ( connectionName , collection , cb ) {
118
+ adapter . registerConnection = function registerConnection ( connection , collection , cb ) {
119
119
120
- var url = urlForConfig ( collection . adapter . config ) ;
120
+ var url = urlForConfig ( connection ) ;
121
121
var db = nano ( url ) ;
122
122
123
- db . db . get ( collection . identity , gotDatabase ) ;
123
+ db . db . get ( connection . identity , gotDatabase ) ;
124
+
124
125
125
126
function gotDatabase ( err ) {
126
127
if ( err && err . status_code == 404 && err . reason == 'no_db_file' ) {
127
- db . db . create ( collection . identity , createdDB ) ;
128
+ db . db . create ( connection . identity , createdDB ) ;
128
129
} else {
129
- registry . collection ( collection . identity , collection ) ;
130
- registry . db ( collection . identity , nano ( url + collection . identity ) ) ;
130
+ registry . collection ( connection . identity , collection ) ;
131
+ registry . db ( connection . identity , nano ( url + connection . identity ) ) ;
131
132
cb ( ) ;
132
133
}
133
134
}
134
135
135
136
function createdDB ( err ) {
136
- if ( err ) cb ( err ) ;
137
- else adapter . registerCollection ( collection , cb ) ;
137
+ if ( err ) {
138
+ console . log ( "Connection Error! " + err ) ;
139
+ cb ( err ) ;
140
+ }
141
+ else {
142
+ console . log ( "Register again!" ) ;
143
+ adapter . registerConnection ( connection , cb ) ;
144
+ }
138
145
}
139
146
} ;
140
147
@@ -162,8 +169,9 @@ adapter.teardown = function teardown(cb) {
162
169
* @return {[type] } [description]
163
170
*/
164
171
adapter . describe = function describe ( connectionName , collectionName , cb ) {
165
- var collection = registry . collection ( collectionName ) ;
166
- if ( ! collection ) return cb ( new Error ( 'no such collection' ) ) ;
172
+ var collection = registry . collection ( connectionName ) ;
173
+ if ( ! collection )
174
+ return cb ( new Error ( 'no such collection' ) ) ;
167
175
cb ( null , collection . definition ) ;
168
176
} ;
169
177
@@ -179,9 +187,9 @@ adapter.describe = function describe(connectionName, collectionName, cb) {
179
187
* @param {Function } cb [description]
180
188
* @return {[type] } [description]
181
189
*/
182
- adapter . drop = function drop ( collectionName , relations , cb ) {
190
+ adapter . drop = function drop ( connectionName , collectionName , relations , cb ) {
183
191
// If you need to access your private data for this collection:
184
- var collection = registry . collection ( collectionName ) ;
192
+ var collection = registry . collection ( connectionName ) ;
185
193
186
194
var db = registry . db ( collectionName ) ;
187
195
db . db . destroy ( cb ) ;
@@ -204,11 +212,11 @@ adapter.drop = function drop(collectionName, relations, cb) {
204
212
*/
205
213
adapter . find = find ;
206
214
207
- function find ( collectionName , options , cb , round ) {
215
+ function find ( connectionName , collectionName , options , cb , round ) {
208
216
if ( 'number' != typeof round ) round = 0 ;
209
217
210
218
// If you need to access your private data for this collection:
211
- var db = registry . db ( collectionName ) ;
219
+ var db = registry . db ( connectionName ) ;
212
220
213
221
var dbOptions = { } ;
214
222
if ( options . limit ) dbOptions . limit = options . limit ;
@@ -276,10 +284,10 @@ function find(collectionName, options, cb, round) {
276
284
* @param {Function } cb [description]
277
285
* @return {[type] } [description]
278
286
*/
279
- adapter . create = function create ( collectionName , values , cb ) {
287
+ adapter . create = function create ( connectionName , collectionName , values , cb ) {
280
288
281
289
282
- var db = registry . db ( collectionName ) ;
290
+ var db = registry . db ( connectionName ) ;
283
291
284
292
db . insert ( docForIngestion ( values ) , replied ) ;
285
293
@@ -305,15 +313,15 @@ adapter.create = function create(collectionName, values, cb) {
305
313
* @param {Function } cb [description]
306
314
* @return {[type] } [description]
307
315
*/
308
- adapter . update = function update ( collectionName , options , values , cb ) {
316
+ adapter . update = function update ( connectionName , collectionName , options , values , cb ) {
309
317
310
318
var searchAttributes = Object . keys ( options . where ) ;
311
319
if ( searchAttributes . length != 1 )
312
320
return cb ( new Error ( 'only support updating one object by id' ) ) ;
313
321
if ( searchAttributes [ 0 ] != 'id' )
314
322
return cb ( new Error ( 'only support updating one object by id' ) ) ;
315
323
316
- var db = registry . db ( collectionName ) ;
324
+ var db = registry . db ( connectionName ) ;
317
325
318
326
db . insert ( docForIngestion ( values ) , options . where . id , replied ) ;
319
327
@@ -336,7 +344,7 @@ adapter.update = function update(collectionName, options, values, cb) {
336
344
* @param {Function } cb [description]
337
345
* @return {[type] } [description]
338
346
*/
339
- adapter . destroy = function destroy ( collectionName , options , cb ) {
347
+ adapter . destroy = function destroy ( connectionName , collectionName , options , cb ) {
340
348
341
349
} ;
342
350
@@ -349,8 +357,8 @@ adapter.destroy = function destroy(collectionName, options, cb) {
349
357
350
358
/// Authenticate
351
359
352
- adapter . authenticate = function authenticate ( collectionName , username , password , cb ) {
353
- var db = registry . db ( collectionName ) ;
360
+ adapter . authenticate = function authenticate ( connectionName , collectionName , username , password , cb ) {
361
+ var db = registry . db ( connectionName ) ;
354
362
355
363
db . auth ( username , password , replied ) ;
356
364
@@ -368,8 +376,8 @@ adapter.authenticate = function authenticate(collectionName, username, password,
368
376
369
377
/// Session
370
378
371
- adapter . session = function session ( collectionName , sid , cb ) {
372
- var collection = registry . collection ( collectionName ) ;
379
+ adapter . session = function session ( connectionName , collectionName , sid , cb ) {
380
+ var collection = registry . collection ( connectionName ) ;
373
381
374
382
var sessionDb = nano ( {
375
383
url : urlForConfig ( collection . adapter . config ) ,
@@ -383,11 +391,11 @@ adapter.session = function session(collectionName, sid, cb) {
383
391
384
392
/// Merge
385
393
386
- adapter . merge = function adapterMerge ( collectionName , id , attrs , cb , attempts ) {
394
+ adapter . merge = function adapterMerge ( connectionName , collectionName , id , attrs , cb , attempts ) {
387
395
var doc ;
388
- var db = registry . db ( collectionName ) ;
396
+ var db = registry . db ( connectionName ) ;
389
397
390
- var coll = registry . collection ( collectionName ) ;
398
+ var coll = registry . collection ( connectionName ) ;
391
399
392
400
if ( 'number' != typeof attempts ) attempts = 0 ;
393
401
else if ( attempts > 0 ) {
@@ -448,15 +456,15 @@ adapter.merge = function adapterMerge(collectionName, id, attrs, cb, attempts) {
448
456
449
457
/// View
450
458
451
- adapter . view = function view ( collectionName , viewName , options , cb , round ) {
459
+ adapter . view = function view ( connectionName , collectionName , viewName , options , cb , round ) {
452
460
if ( 'number' != typeof round ) round = 0 ;
453
- var db = registry . db ( collectionName ) ;
461
+ var db = registry . db ( connectionName ) ;
454
462
455
463
db . view ( 'views' , viewName , options , viewResult ) ;
456
464
457
465
function viewResult ( err , results ) {
458
466
if ( err && err . status_code == 404 && round < 2 )
459
- populateView ( collectionName , viewName , populatedView ) ;
467
+ populateView ( connectionName , collectionName , viewName , populatedView ) ;
460
468
else if ( err ) cb ( err ) ;
461
469
else cb ( null , ( results && results . rows && results . rows || [ ] ) . map ( prop ( 'value' ) ) . map ( docForReply ) ) ;
462
470
}
@@ -467,8 +475,8 @@ adapter.view = function view(collectionName, viewName, options, cb, round) {
467
475
}
468
476
} ;
469
477
470
- function populateView ( collectionName , viewName , cb ) {
471
- var collection = registry . collection ( collectionName ) ;
478
+ function populateView ( connectionName , collectionName , viewName , cb ) {
479
+ var collection = registry . collection ( connectionName ) ;
472
480
473
481
var view = collection . views && collection . views [ viewName ] ;
474
482
if ( ! view ) return cb ( new Error ( 'No view named ' + viewName + ' defined in model ' + collectionName ) ) ;
0 commit comments