<commit_before>'use strict';

const async = require('async'),
      q = require('q');

const couch = require('app/modules/database').couch;

module.exports = repositoryFactory;

function repositoryFactory(dbName, repo) {

  const db = couch.database(dbName);

  repo = typeof repo === 'object' ? repo : {};

  Object.assign(repo, {

    save(obj) {
      return q.Promise((resolve, reject) => {
        getObjectArguments(obj)
          .then((args) => {
            db.save.apply(db, args.concat([obj.toJSON(), (err, response) => {
              if (err) reject(err);
              else {
                obj._rev = response.rev;
                resolve(obj);
              }
            }]));
          }, reject);
      });
    },

          });
        }));
    },
<commit_msg>add methods remove() and clear() to repositoryFactory<commit_after>'use strict';

const async = require('async'),
      q = require('q');

const couch = require('app/modules/database').couch;

module.exports = repositoryFactory;

function repositoryFactory(dbName, repo) {

  const db = couch.database(dbName);

  repo = typeof repo === 'object' ? repo : {};

  Object.assign(repo, {

    save(obj) {
      return q.Promise((resolve, reject) => {
        getObjectArguments(obj)
          .then((args) => {
            db.save.apply(db, args.concat([obj.toJSON(), (err, response) => {
              if (err) reject(err);
              else {
                obj._rev = response.rev;
                resolve(obj);
              }
            }]));
          }, reject);
      });
    },

    remove(obj) {
      return q.Promise((resolve, reject) => {
        getObjectArguments(obj)
          .then((args) => {
            db.remove.apply(db, args.concat([(err, response) => {
              if (err) reject(err);
              else resolve(response);
            }]));
          }, reject);
      });
    },

    clear() {
      return repo.view('byId')
        .then((results) => q.Promise((resolve, reject) => {
          async.each(results, (obj, cb) => {
            repo.remove(obj).nodeify(cb);
          }, (err) => {
            if (err) reject(err);
            else resolve(true);
          });
        }));
    },

{'fraction_non_alphanumeric': 0.16681776971894832, 'fraction_numerical': 0.0, 'mean_word_length': 1.7866161616161615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '6792217', 'n_tokens_mistral': 643, 'n_tokens_neox': 629, 'n_words': 121}