all files / lib/waterline/adapter/ stream.js

58.33% Statements 7/12
25% Branches 1/4
100% Functions 1/1
60% Lines 6/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                                         
/**
 * Module Dependencies
 */
 
var normalize = require('../utils/normalize');
var hasOwnProperty = require('../utils/helpers').object.hasOwnProperty;
 
/**
 * Stream Normalization
 */
 
module.exports = {
 
  // stream.write() is used to send data
  // Must call stream.end() to complete stream
  stream: function(criteria, stream, metaContainer) {
 
    // Normalize Arguments
    criteria = normalize.criteria(criteria);
 
    // Build Default Error Message
    var err = 'No stream() method defined in adapter!';
 
    // Find the connection to run this on
    Eif (!hasOwnProperty(this.dictionary, 'stream')) return stream.end(new Error(err));
 
    var connName = this.dictionary.stream;
    var adapter = this.connections[connName]._adapter;
 
    if (!hasOwnProperty(adapter, 'stream')) return stream.end(new Error(err));
    adapter.stream(connName, this.collection, criteria, stream, metaContainer);
  }
 
};