Skip to content

Commit 6ff10e4

Browse files
committed
Updated the method signatures to work with 0.10.x, WIP
1 parent 4f8a90c commit 6ff10e4

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

index.js

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,33 @@ adapter.defaults = {
115115
* @param {Function} cb [description]
116116
* @return {[type]} [description]
117117
*/
118-
adapter.registerConnection = function registerConnection(connectionName, collection, cb) {
118+
adapter.registerConnection = function registerConnection(connection, collection, cb) {
119119

120-
var url = urlForConfig(collection.adapter.config);
120+
var url = urlForConfig(connection);
121121
var db = nano(url);
122122

123-
db.db.get(collection.identity, gotDatabase);
123+
db.db.get(connection.identity, gotDatabase);
124+
124125

125126
function gotDatabase(err) {
126127
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);
128129
} 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));
131132
cb();
132133
}
133134
}
134135

135136
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+
}
138145
}
139146
};
140147

@@ -162,8 +169,9 @@ adapter.teardown = function teardown(cb) {
162169
* @return {[type]} [description]
163170
*/
164171
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'));
167175
cb(null, collection.definition);
168176
};
169177

@@ -179,9 +187,9 @@ adapter.describe = function describe(connectionName, collectionName, cb) {
179187
* @param {Function} cb [description]
180188
* @return {[type]} [description]
181189
*/
182-
adapter.drop = function drop(collectionName, relations, cb) {
190+
adapter.drop = function drop(connectionName, collectionName, relations, cb) {
183191
// If you need to access your private data for this collection:
184-
var collection = registry.collection(collectionName);
192+
var collection = registry.collection(connectionName);
185193

186194
var db = registry.db(collectionName);
187195
db.db.destroy(cb);
@@ -204,11 +212,11 @@ adapter.drop = function drop(collectionName, relations, cb) {
204212
*/
205213
adapter.find = find;
206214

207-
function find(collectionName, options, cb, round) {
215+
function find(connectionName, collectionName, options, cb, round) {
208216
if ('number' != typeof round) round = 0;
209217

210218
// If you need to access your private data for this collection:
211-
var db = registry.db(collectionName);
219+
var db = registry.db(connectionName);
212220

213221
var dbOptions = {};
214222
if (options.limit) dbOptions.limit = options.limit;
@@ -276,10 +284,10 @@ function find(collectionName, options, cb, round) {
276284
* @param {Function} cb [description]
277285
* @return {[type]} [description]
278286
*/
279-
adapter.create = function create(collectionName, values, cb) {
287+
adapter.create = function create(connectionName, collectionName, values, cb) {
280288

281289

282-
var db = registry.db(collectionName);
290+
var db = registry.db(connectionName);
283291

284292
db.insert(docForIngestion(values), replied);
285293

@@ -305,15 +313,15 @@ adapter.create = function create(collectionName, values, cb) {
305313
* @param {Function} cb [description]
306314
* @return {[type]} [description]
307315
*/
308-
adapter.update = function update(collectionName, options, values, cb) {
316+
adapter.update = function update(connectionName, collectionName, options, values, cb) {
309317

310318
var searchAttributes = Object.keys(options.where);
311319
if (searchAttributes.length != 1)
312320
return cb(new Error('only support updating one object by id'));
313321
if (searchAttributes[0] != 'id')
314322
return cb(new Error('only support updating one object by id'));
315323

316-
var db = registry.db(collectionName);
324+
var db = registry.db(connectionName);
317325

318326
db.insert(docForIngestion(values), options.where.id, replied);
319327

@@ -336,7 +344,7 @@ adapter.update = function update(collectionName, options, values, cb) {
336344
* @param {Function} cb [description]
337345
* @return {[type]} [description]
338346
*/
339-
adapter.destroy = function destroy(collectionName, options, cb) {
347+
adapter.destroy = function destroy(connectionName, collectionName, options, cb) {
340348

341349
};
342350

@@ -349,8 +357,8 @@ adapter.destroy = function destroy(collectionName, options, cb) {
349357

350358
/// Authenticate
351359

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);
354362

355363
db.auth(username, password, replied);
356364

@@ -368,8 +376,8 @@ adapter.authenticate = function authenticate(collectionName, username, password,
368376

369377
/// Session
370378

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);
373381

374382
var sessionDb = nano({
375383
url: urlForConfig(collection.adapter.config),
@@ -383,11 +391,11 @@ adapter.session = function session(collectionName, sid, cb) {
383391

384392
/// Merge
385393

386-
adapter.merge = function adapterMerge(collectionName, id, attrs, cb, attempts) {
394+
adapter.merge = function adapterMerge(connectionName, collectionName, id, attrs, cb, attempts) {
387395
var doc;
388-
var db = registry.db(collectionName);
396+
var db = registry.db(connectionName);
389397

390-
var coll = registry.collection(collectionName);
398+
var coll = registry.collection(connectionName);
391399

392400
if ('number' != typeof attempts) attempts = 0;
393401
else if (attempts > 0) {
@@ -448,15 +456,15 @@ adapter.merge = function adapterMerge(collectionName, id, attrs, cb, attempts) {
448456

449457
/// View
450458

451-
adapter.view = function view(collectionName, viewName, options, cb, round) {
459+
adapter.view = function view(connectionName, collectionName, viewName, options, cb, round) {
452460
if ('number' != typeof round) round = 0;
453-
var db = registry.db(collectionName);
461+
var db = registry.db(connectionName);
454462

455463
db.view('views', viewName, options, viewResult);
456464

457465
function viewResult(err, results) {
458466
if (err && err.status_code == 404 && round < 2)
459-
populateView(collectionName, viewName, populatedView);
467+
populateView(connectionName, collectionName, viewName, populatedView);
460468
else if (err) cb(err);
461469
else cb(null, (results && results.rows && results.rows || []).map(prop('value')).map(docForReply));
462470
}
@@ -467,8 +475,8 @@ adapter.view = function view(collectionName, viewName, options, cb, round) {
467475
}
468476
};
469477

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);
472480

473481
var view = collection.views && collection.views[viewName];
474482
if (! view) return cb(new Error('No view named ' + viewName + ' defined in model ' + collectionName));

0 commit comments

Comments
 (0)