<commit_before>'use strict';

module.exports = function(name, db, options) {
    var _ = require('lodash')
      , configuration = _.extend({view: name}, options)
      , service = require('./service')(db, {
            view: configuration.view,
            fields: configuration.fields,
            id: configuration.id
        })
      , router = require('./router')(service, {
            fields: configuration.fields
        })
      , middleware = require('express').Router();

    middleware.route('/')
        .get(router.list)
        .post(router.create);
    
    middleware.route('/:id')
        .get(router.read)
        .put(router.update);

    return middleware;
};
<commit_msg>added using provided nano instance if available<commit_after>'use strict';

module.exports = function(name, db, options) {
    var _ = require('lodash')
      , couch = (typeof db === 'string') ? require('nano')(db) : db
      , configuration = _.extend({view: name}, options)
      , service = require('./service')(couch, {
            view: configuration.view,
            fields: configuration.fields,
            id: configuration.id
        })
      , router = require('./router')(service, {
            fields: configuration.fields
        })
      , middleware = require('express').Router();

    middleware.route('/')
        .get(router.list)
        .post(router.create);
    
    middleware.route('/:id')
        .get(router.read)
        .put(router.update);

    return middleware;
};

{'fraction_non_alphanumeric': 0.15492957746478872, 'fraction_numerical': 0.0, 'mean_word_length': 2.243478260869565, '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': '5234121', 'n_tokens_mistral': 416, 'n_tokens_neox': 408, 'n_words': 80}