Skip to content

Updates and promises #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ To run test with TingoDB: ```./test.sh --quick --single=misc-test --db=tingodb``
Usage
======

npm install tingodb
npm i --save https://github.com/lcnvdl/tingodb.git

As stated, the API is fully compatible with the MongoDB [v1.4 API](http://mongodb.github.io/node-mongodb-native/1.4/). The only differences are the initialization and getting the Db object. Consider this MongoDB code:

28 changes: 28 additions & 0 deletions lib/defer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function defer() {
var value, error, resolved, rejected
var deferred = function(err, value) {
if (err) deferred.reject(err)
else deferred.resolve(value)
}
deferred.resolve = function(v) {
if (!resolved && !rejected) {
value = v
resolved = true
}
}
deferred.reject = function(e) {
if (!resolved && !rejected) {
error = e
rejected = true
}
}
deferred.promise = new Promise(function(resolve, reject) {
if (resolved) resolve(value)
if (rejected) reject(error)
deferred.resolve = resolve
deferred.reject = reject
})
return deferred
}

module.exports = defer
8 changes: 4 additions & 4 deletions lib/tbinary.js
Original file line number Diff line number Diff line change
@@ -50,13 +50,13 @@ function Binary(buffer, subType) {
// Only accept Buffer, Uint8Array or Arrays
if (_.isString(buffer)) {
// Different ways of writing the length of the string for the different types
this.buffer = new Buffer(buffer);
this.buffer = Buffer.from(buffer);
} else {
this.buffer = buffer;
}
this.position = buffer.length;
} else {
this.buffer = new Buffer(Binary.BUFFER_SIZE);
this.buffer = Buffer.alloc(Binary.BUFFER_SIZE);
// Set position to start of buffer
this.position = 0;
}
@@ -90,7 +90,7 @@ Binary.prototype.put = function put(byte_value) {

if (Buffer.isBuffer(this.buffer)) {
// Create additional overflow buffer
buffer = new Buffer(Binary.BUFFER_SIZE + this.buffer.length);
buffer = Buffer.from(Binary.BUFFER_SIZE + this.buffer.length);
// Combine the two buffers together
this.buffer.copy(buffer, 0, 0, this.buffer.length);
this.buffer = buffer;
@@ -132,7 +132,7 @@ Binary.prototype.write = function write(string, offset) {
var buffer = null;
// If we are in node.js
if (Buffer.isBuffer(this.buffer)) {
buffer = new Buffer(this.buffer.length + string.length);
buffer = Buffer.alloc(this.buffer.length + string.length);
this.buffer.copy(buffer, 0, 0, this.buffer.length);
} else if (Buffer.isBuffer(this.buffer)) {
// Create a new buffer
Loading