<commit_before>var db_helper = require('./connection');

var Queriable = function () {

  this.onDocLoad = function (fn) {
    this.onDocLoadFn = fn;
  };

  this.find = function (id, cb) {
    var db = db_helper.connection(),
        self = this;

    db.get(id, function (err, doc) {
      if (err) {
        return cb(err, null);
      }

      if(doc) {
        try {
          var loaded_doc = self.onDocLoadFn(doc);
        } catch(ex) {
          //dumpError(ex);
          return cb(ex,null);
        }
        return cb(null, loaded_doc);
      } else {
        return cb("item does not exist", null);
      }
    });
  };

  this._view = function (view_name, options, cb) {
    var db = db_helper.connection(), 
        view_name = view_name.split("/")
        self = this;
    db.view(view_name[0],view_name[1], options, function (err, docs) {
      if (err) {
        return cb(err, null);
      }

      var model_collection = [];

      docs.rows.forEach(function (doc,index) {
        model_collection.push(self.onDocLoadFn(doc.doc));
      });

      return cb(null, model_collection);
    });<commit_msg>find by property<commit_after>var db_helper = require('./connection');

var Queriable = function () {

  this.onDocLoad = function (fn) {
    this.onDocLoadFn = fn;
  };

  this.find = function (id, cb) {
    var db = db_helper.connection(),
        self = this;

    db.get(id, function (err, doc) {
      if (err) {
        return cb(err, null);
      }

      if(doc) {
        try {
          var loaded_doc = self.onDocLoadFn(doc);
        } catch(ex) {
          //dumpError(ex);
          return cb(ex,null);
        }
        return cb(null, loaded_doc);
      } else {
        return cb("item does not exist", null);
      }
    });
  };

  this._view = function (view_name, options, cb) {
    var db = db_helper.connection(), 
        view_name = view_name.split("/")
        self = this;
    db.view(view_name[0],view_name[1], options, function (err, docs) {

      if (err) {
        return cb(err, null);
      }

      var model_collection = [];

      docs.rows.forEach(function (doc,index) {
        var place = docs.rows.length>1?"doc":"value";
        model_collection.push(self.onDocLoadFn(doc[place]));
      });

      return cb(null, model_collection);
    });
{'fraction_non_alphanumeric': 0.14850195397307858, 'fraction_numerical': 0.0021710811984368217, 'mean_word_length': 2.0597609561752988, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6833014', 'n_tokens_mistral': 768, 'n_tokens_neox': 743, 'n_words': 161}