<commit_before>var backsync = require( "backsync" );
module.exports = function ( connection ) {
    var Cursor = connection.Cursor;

    var update = function ( model, options, callback ) {
        var obj = ( model.toJSON ) ? model.toJSON() : model;
        var cursor = new Cursor();
        cursor.once( "error", callback );
        cursor.once( "finish", function () {
            callback( null, obj );
        });

        ( !options.remove ) 
            ? cursor.write( obj ) 
            : cursor.remove({ id: model.id });

        cursor.end();
    }

    var read = function ( model, options, callback ) {
        new Cursor()
            .find({ id: model.id })
            .limit( 1 )
            .once( "error", callback )
            .once( "data", function ( obj ) {
                callback( null, obj );
                callback = null;
            })
            .once( "end", function () {
                if ( callback ) {
                    callback( new backsync.NotFoundError( model.id ) );
                }
            });
    }


    return backsync()
        .create( update )
        .update( update )
        .read( read )
        .patch( function ( model, options, callback ) {
            read( model, { silent: true }, function ( err, obj ) {
                if ( err ) return callback( err );
                obj = _.extend( {}, obj, options.attrs );
                update( obj, {}, callback );
            });
        })
        .search( function ( collection, options, callback ) {
            options.data || ( options.data = {} );
            var data = _.clone( options.data || {} );
            delete data[ "$sort" ];
            delete data[ "$skip" ];
            delete data[ "$limit" ];

            var results = [];
            var cursor = new Cursor()
                .find( data )
                .sort( options.data.$sort || null )
                .skip( options.data.$skip || 0 )
                .limit( options.data.$limit || Infinity )
                .once( "error", callback )
                .once( "end", function() { callback( null, results ); })
                .on( "data", function ( obj ) { results.push( obj ) } )
        })
        .delete( function ( model, options, callback ) {
            update( model, _.extend({ remove: true }, options ), callback );
        });
}<commit_msg>Removes the dependency on underscore<commit_after>var backsync = require( "backsync" );
module.exports = function ( connection ) {
    var Cursor = connection.Cursor;

    var update = function ( model, options, callback ) {
        var obj = ( model.toJSON ) ? model.toJSON() : model;
        var cursor = new Cursor();
        cursor.once( "error", callback );
        cursor.once( "finish", function () {
            callback( null, obj );
        });

        ( !options.remove ) 
            ? cursor.write( obj ) 
            : cursor.remove({ id: model.id });

        cursor.end();
    }

    var read = function ( model, options, callback ) {
        new Cursor()
            .find({ id: model.id })
            .limit( 1 )
            .once( "error", callback )
            .once( "data", function ( obj ) {
                callback( null, obj );
                callback = null;
            })
            .once( "end", function () {
                if ( callback ) {
                    callback( new backsync.NotFoundError( model.id ) );
                }
            });
    }


    return backsync()
        .create( update )
        .update( update )
        .read( read )
        .patch( function ( model, options, callback ) {
            read( model, { silent: true }, function ( err, obj ) {
                if ( err ) return callback( err );
                obj = extend( {}, obj, options.attrs );
                update( obj, {}, callback );
            });
        })
        .search( function ( collection, options, callback ) {
            options.data || ( options.data = {} );
            var data = extend( {}, options.data || {} );
            delete data[ "$sort" ];
            delete data[ "$skip" ];
            delete data[ "$limit" ];

            var results = [];
            var cursor = new Cursor()
                .find( data )
                .sort( options.data.$sort || null )
                .skip( options.data.$skip || 0 )
                .limit( options.data.$limit || Infinity )
                .once( "error", callback )
                .once( "end", function() { callback( null, results ); })
                .on( "data", function ( obj ) { results.push( obj ) } )
        })
        .delete( function ( model, options, callback ) {
            update( model, extend({ remove: true }, options ), callback );
        });
}

function extend ( obj ) {
    [].slice.call(arguments, 1).forEach(function(source) {
      if (source) {
        for (var prop in source) {
          obj[prop] = source[prop];
        }
      }
    });
    return obj;
}
{'fraction_non_alphanumeric': 0.14282824195832491, 'fraction_numerical': 0.0010115314586283633, 'mean_word_length': 1.404669260700389, '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': '6751525', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1260, 'n_words': 362}