wrapper.js
function wrapQueryMethod(fn, ctx) {
    return function() {
        // Obtain function arguments
        var args = [].slice.call(arguments);
        
        // Return a thunkified function that receives a done callback
        return function(done) {
            // Add a custom callback to provided args
            args.push(function(err, result) {
                // Query failed?
                if (err) {
                    return done(err);
                }

                // Query succeeded
                done(null, result);
            });

            // Execute the query
            fn.apply(ctx, args);
        };
    };
}
function wrapQueryMethod(fn, ctx) {
    return function() {
        // Obtain function arguments
        var args = [].slice.call(arguments);
        
        // Return a thunkified function that receives a done callback
        return function(done) {
            // Add a custom callback to provided args
            args.push(function(err, result) {
                // Query failed?
                if (err) {
                    return done(err);
                }

                // Query succeeded
                done(null, result);
            });

            // Execute the query
            fn.apply(ctx, args);
        };
    };
}
function wrapQueryMethod ( fn , ctx ) { return function ( ) { // Obtain function arguments var args = [ ] . slice . call ( arguments ) ; // Return a thunkified function that receives a done callback return function ( done ) { // Add a custom callback to provided args args . push ( function ( err , result ) { // Query failed? if ( err ) { return done ( err ) ; } // Query succeeded done ( null , result ) ; } ) ; // Execute the query fn . apply ( ctx , args ) ; } ; } ; }
Thunkify query methods
Thunkify query methods