New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sails-mongo

Package Overview
Dependencies
Maintainers
4
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sails-mongo - npm Package Compare versions

Comparing version 0.10.4 to 0.10.5

84

lib/adapter.js

@@ -9,4 +9,7 @@ /*---------------------------------------------------------------

var Errors = require('waterline-errors').adapter;
var ObjectId = require('mongodb').ObjectID;
var _runJoins = require('waterline-cursor');
var util = require('util');
module.exports = (function() {

@@ -59,3 +62,3 @@

noDelay: false,
keepAlive: true,
keepAlive: 0,
connectTimeoutMS: 5000,

@@ -92,4 +95,12 @@ socketTimeoutMS: 5000

// Create a new active connection
new Connection(connection, function(err, db) {
if(err) return cb(err);
new Connection(connection, function(_err, db) {
if(_err) {
return cb((function _createError(){
var msg = util.format('Failed to connect to MongoDB. Are you sure your configured Mongo instance is running?\n Error details:\n%s', util.inspect(_err, false, null));
var err = new Error(msg);
err.originalError = _err;
return err;
})());
}
connections[connection.identity].connection = db;

@@ -116,14 +127,14 @@

teardown: function(connectionName, cb) {
if(!connections[connectionName]) return cb();
// Drain the connection pool if available
connections[connectionName].connection.db.close(function(err) {
if(err) return cb(err);
// Remove the connection from the registry
delete connections[connectionName];
cb();
});
teardown: function (conn, cb) {
if (typeof conn == 'function') {
cb = conn;
conn = null;
}
if (conn == null) {
connections = {};
return cb();
}
if(!connections[conn]) return cb();
delete connections[conn];
cb();
},

@@ -224,2 +235,26 @@

/**
* Mongo object with mongoDB native methods
*/
mongo: {
/**
* ObjectId
*
* Return a Mongo ObjectID from a string
*
* @param {String} id
*/
objectId: function(id){
if(!id) return null;
try {
return new ObjectId(id);
} catch(err) {
return null;
}
}
},
/**
* Create

@@ -431,3 +466,22 @@ *

/**
* Stream
*
* Stream one or more documents from the collection
* using where, limit, skip, and order
* In where: handle `or`, `and`, and `like` queries
*
* @param {String} connectionName
* @param {String} collectionName
* @param {Object} options
* @param {Object} stream
*/
stream: function(connectionName, collectionName, options, stream) {
options = options || {};
var connectionObject = connections[connectionName];
var collection = connectionObject.collections[collectionName];
collection.stream(options, stream);
},
identity: 'sails-mongo'

@@ -434,0 +488,0 @@ };

@@ -108,2 +108,57 @@

/**
* Stream Documents
*
* @param {Object} criteria
* @param {Object} stream
* @api public
*/
Collection.prototype.stream = function find(criteria, stream) {
var self = this,
query;
// Ignore `select` from waterline core
if (typeof criteria === 'object') {
delete criteria.select;
}
// Catch errors from building query and return to the callback
try {
query = new Query(criteria, this.schema);
} catch(err) {
return stream.end(err); // End stream
}
var collection = this.connection.db.collection(self.identity);
var where = query.criteria.where || {};
var queryOptions = _.omit(query.criteria, 'where');
// Run Normal Query on collection
var dbStream = collection.find(where, queryOptions).stream();
// For each data item
dbStream.on('data', function(item) {
// Pause stream
dbStream.pause();
var obj = utils.rewriteIds([item], self.schema)[0];
stream.write(obj, function() {
dbStream.resume();
});
});
// Handle error, an 'end' event will be emitted after this as well
dbStream.on('error', function(err) {
stream.end(err); // End stream
});
// all rows have been received
dbStream.on('close', function() {
stream.end();
});
};
/**
* Insert A New Document

@@ -110,0 +165,0 @@ *

@@ -120,2 +120,5 @@

// Support for encoded auth credentials
connectionOptions.uri_decode_auth = this.config.uri_decode_auth || false;
// Build A Mongo Connection String

@@ -122,0 +125,0 @@ var connectionString = 'mongodb://';

16

lib/query/index.js

@@ -196,4 +196,4 @@

modifier = _.isArray(val) ? '$nin' : '$ne';
val = self.parseValue(field, modifier, val);
modifier = _.isArray(val) ? '$nin' : '$ne';
obj[modifier] = val;

@@ -317,6 +317,14 @@ return obj;

// If we can verify that the field is NOT a string type, translate
// certain values into booleans or null. Otherwise they'll be left
// certain values into booleans, date or null. Otherwise they'll be left
// as strings.
if (hop(self.schema, field) && self.schema[field].type != 'string') {
if(self.schema[field].type === 'integer'){
return parseInt(val);
}
if(self.schema[field].type === 'float'){
return parseFloat(val);
}
if (val === "false") {

@@ -369,2 +377,2 @@ return false;

}, {});
};
};

@@ -40,3 +40,7 @@

if(hop.call(model, '_id')) {
model.id = model._id.toString();
// change id to string only if it's necessary
if(typeof model._id === 'object')
model.id = model._id.toString();
else
model.id = model._id;
delete model._id;

@@ -43,0 +47,0 @@ }

{
"name": "sails-mongo",
"version": "0.10.4",
"version": "0.10.5",
"description": "Mongo DB adapter for Sails.js",

@@ -42,3 +42,3 @@ "main": "./lib/adapter.js",

"lodash": "~2.4.1",
"mongodb": "1.4.4",
"mongodb": "1.4.26",
"waterline-errors": "~0.10.0",

@@ -45,0 +45,0 @@ "waterline-cursor": "~0.0.5"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc