<commit_before>'use strict';

var _ = require('lodash');
var monk = require('monk');

module.exports = function(options) {
  var opts = _.defaults({}, options.mongo, {
    collection: 'users'
  });
  var db = monk(opts.db);
  var users = db.get(opts.collection);

  var create = function(attributes) {
    return users.insert(attributes);
  };

  var find = function(query) {
    return users.findOne(query);
  };

  var findByToken = function(token) {
    return users.findOne({ sessionDigests: token });
  };

  var addToken = function(user, token) {
    return users.update({ _id: user._id },
      { $push: { sessionDigests: token }});
  };

  var removeToken = function(user, token) {
    return users.update({ _id: user._id },
      { $pull: { sessionDigests: token }});
  };

  var adapter = {};

  adapter.users = {
    create: create,
    find: find,
    findByToken: findByToken,
    addToken: addToken,
    removeToken: removeToken
  };

  adapter.attrs = {
    all: function(user) { return user; }
  };

  return adapter;
};<commit_msg>Exposed database.<commit_after>'use strict';

var _ = require('lodash');
var monk = require('monk');

module.exports = function(options) {
  var opts = _.defaults({}, options.mongo, {
    collection: 'users'
  });
  var db = monk(opts.db);
  var users = db.get(opts.collection);

  var create = function(attributes) {
    return users.insert(attributes);
  };

  var find = function(query) {
    return users.findOne(query);
  };

  var findByToken = function(token) {
    return users.findOne({ sessionDigests: token });
  };

  var addToken = function(user, token) {
    return users.update({ _id: user._id },
      { $push: { sessionDigests: token }});
  };

  var removeToken = function(user, token) {
    return users.update({ _id: user._id },
      { $pull: { sessionDigests: token }});
  };

  var adapter = {};

  adapter.users = {
    create: create,
    find: find,
    findByToken: findByToken,
    addToken: addToken,
    removeToken: removeToken
  };

  adapter.attrs = {
    all: function(user) { return user; }
  };

  adapter._db = db;

  return adapter;
};
{'fraction_non_alphanumeric': 0.15275813295615276, 'fraction_numerical': 0.0, 'mean_word_length': 3.16078431372549, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3324959', 'n_tokens_mistral': 706, 'n_tokens_neox': 680, 'n_words': 163}