Comparing version 0.1.9 to 0.2.0
(function() { | ||
var Boom, CB, Couchbase, Database; | ||
var Boom, CB, Couchbase, Database, Q, errorHandler; | ||
@@ -8,7 +8,9 @@ CB = require('couchbase'); | ||
Couchbase = (function() { | ||
Couchbase.bucket = null; | ||
Q = require('q'); | ||
Couchbase.couchbase = null; | ||
errorHandler = function(ex) { | ||
return Boom.serverTimeout(ex.message); | ||
}; | ||
Couchbase = (function() { | ||
function Couchbase(options) { | ||
@@ -19,45 +21,44 @@ var cluster, host; | ||
this.bucket = cluster.openBucket(options.name); | ||
this.couchbase = CB; | ||
} | ||
Couchbase.prototype._execute = function(method) { | ||
var args, callback, ex; | ||
try { | ||
args = Array.prototype.slice.call(arguments).slice(1); | ||
callback = args[args.length - 1]; | ||
args[args.length - 1] = function(err, data) { | ||
if (err) { | ||
return callback(Boom.badRequest(err)); | ||
} else { | ||
return callback(data); | ||
} | ||
}; | ||
return this.bucket[method].apply(this.bucket, args); | ||
} catch (_error) { | ||
ex = _error; | ||
console.log("[database] '" + method + "' function caused this error."); | ||
console.trace(ex); | ||
return callback(Boom.serverTimeout(ex.message)); | ||
} | ||
Couchbase.prototype._exec = function(name) { | ||
return Q.npost(this.bucket, name, Array.prototype.slice.call(arguments, 1)).fail(errorHandler); | ||
}; | ||
Couchbase.prototype.get = function(id, callback) { | ||
if (typeof id === 'string') { | ||
return this._execute('get', id, callback); | ||
Couchbase.prototype.create = function(id, doc) { | ||
return this._exec("insert", id, doc); | ||
}; | ||
Couchbase.prototype.get = function(id) { | ||
if (id.constructor === Array) { | ||
return this._exec("getMulti", id); | ||
} else { | ||
return this._execute('getMulti', id, callback); | ||
return this._exec("get", id); | ||
} | ||
}; | ||
Couchbase.prototype.list = function(design, view, callback) { | ||
var query, viewQuery; | ||
viewQuery = CB.ViewQuery; | ||
query = viewQuery.from(design, view); | ||
return this._execute('query', query, callback); | ||
Couchbase.prototype.replace = function(id, doc) { | ||
return this._exec("replace", id, doc); | ||
}; | ||
Couchbase.prototype.create = function(id, doc, callback) { | ||
return this._execute('insert', id, doc, callback); | ||
Couchbase.prototype.upsert = function(id, doc) { | ||
return this._exec("upsert", id, doc); | ||
}; | ||
Couchbase.prototype.remove = function(id) { | ||
return this._exec("remove", id); | ||
}; | ||
Couchbase.prototype.counter = function(id, step) { | ||
return this._exec("counter", id, step); | ||
}; | ||
Couchbase.prototype.from = function(design, view) { | ||
return CB.ViewQuery.from(design, view); | ||
}; | ||
Couchbase.prototype.commit = function(query) { | ||
return this._exec("query", query); | ||
}; | ||
return Couchbase; | ||
@@ -64,0 +65,0 @@ |
{ | ||
"name": "puffer", | ||
"description": "Extendable Couchbase ODM for Hapi js", | ||
"version": "0.1.9", | ||
"version": "0.2.0", | ||
"main": "build/main", | ||
@@ -25,5 +25,7 @@ "dependencies": { | ||
"coffee-script": "^1.8.0", | ||
"groc": "^0.8.0", | ||
"gulp": "^3.8.10", | ||
"gulp-coffee": "^2.2.0", | ||
"mocha": "^2.0.1" | ||
"mocha": "^2.0.1", | ||
"node-uuid": "^1.4.2" | ||
}, | ||
@@ -30,0 +32,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
160884
12
1032
7
1