<commit_before>"use strict";

var debug = require('plog')('mambo:scan'),
    util = require('util');

// this.scan('song', {
//         'available': {'EQ': '-1'},
//         'loves': {'NE': 0},
//         'title': 'NOT_NULL',
//         'artist': 'NULL',
//     },
//     {
//         'limit': 10,
//         'startKey': {
//             'id': 100
//         },
//         'fields': ['id', 'title']
//     });

function Scanner(model, alias){
    this.model = model;
    this.alias = alias;
    this.schema = this.model.schema(this.alias);

    this.filter = {};
    this._limit = undefined;
    this._fields = undefined;
    this._startKey = undefined;
    this._count = undefined;
    this._all = false;
}
module.exports = Scanner;

Scanner.prototype.all = function(){
    this._all = true;
    return this;
};

Scanner.prototype.count = function(){
    this._count = true;
    return this;
};

Scanner.prototype.limit = function(l){
    this._limit = l;
    return this;
};

Scanner.prototype.fields = function(f){
    this._fields = f;
    return this;
};

Scanner.prototype.start = function(key){
    this._startKey = key;
    return this;
};

// module.exports.scan('song')
//     // .where('id', 'IN', [1, 2, 3])
//     // .where('loves', '<', 1)
//     // .where('trending', '=', null)
//     // .where('title', '!=', null)
//     // .where('bio', 'NULL')
//     // .where('location', 'NOT_NULL')
//     // .where('started', 'BETWEEN', [1990, 1992])
//     // .fetch(done);
Scanner.prototype.where = function(key, operator, value){
    operator = expandOperator(operator) || operator;
    var f = {};
    f[operator] = value;
    this.filter[key] = f;
    return this;
};

Scanner.prototype.fetch = function(done){
    debug('Fetch called.');
    var opts = {},
        self = this;

    ['limit', 'startKey', 'count', 'fields'].forEach(function(f){
        if(self['_' + f] !== undefined){
            opts[f] = this['_' + f];
        }
    });

    function getNextPage(res, callback){
        if(res.hasMore){
            res.next(function(err, r){
                res.isLastPage = r.isLastPage;
                res.lastEvaluatedKey = r.lastEvaluatedKey;
                res.count += r.count;
                res.hasMore = r.hasMore;
                r.items.forEach(function(item){
                    res.items.push(item);
                });
                return getNextPage(res, callback);
            });
        }
        else{
            debug('Got all pages.  Resolving');
            callback(null, res);
        }
    }<commit_msg>Scope fix...<commit_after>"use strict";

var debug = require('plog')('mambo:scan'),
    util = require('util');

// this.scan('song', {
//         'available': {'EQ': '-1'},
//         'loves': {'NE': 0},
//         'title': 'NOT_NULL',
//         'artist': 'NULL',
//     },
//     {
//         'limit': 10,
//         'startKey': {
//             'id': 100
//         },
//         'fields': ['id', 'title']
//     });

function Scanner(model, alias){
    this.model = model;
    this.alias = alias;
    this.schema = this.model.schema(this.alias);

    this.filter = {};
    this._limit = undefined;
    this._fields = undefined;
    this._startKey = undefined;
    this._count = undefined;
    this._all = false;
}
module.exports = Scanner;

Scanner.prototype.all = function(){
    this._all = true;
    return this;
};

Scanner.prototype.count = function(){
    this._count = true;
    return this;
};

Scanner.prototype.limit = function(l){
    this._limit = l;
    return this;
};

Scanner.prototype.fields = function(f){
    this._fields = f;
    return this;
};

Scanner.prototype.start = function(key){
    this._startKey = key;
    return this;
};

// module.exports.scan('song')
//     // .where('id', 'IN', [1, 2, 3])
//     // .where('loves', '<', 1)
//     // .where('trending', '=', null)
//     // .where('title', '!=', null)
//     // .where('bio', 'NULL')
//     // .where('location', 'NOT_NULL')
//     // .where('started', 'BETWEEN', [1990, 1992])
//     // .fetch(done);
Scanner.prototype.where = function(key, operator, value){
    operator = expandOperator(operator) || operator;
    var f = {};
    f[operator] = value;
    this.filter[key] = f;
    return this;
};

Scanner.prototype.fetch = function(done){
    debug('Fetch called.');
    var opts = {},
        self = this;

    ['limit', 'startKey', 'count', 'fields'].forEach(function(f){
        if(self['_' + f] !== undefined){
            opts[f] = self['_' + f];
        }
    });

    function getNextPage(res, callback){
        if(res.hasMore){
            res.next(function(err, r){
                res.isLastPage = r.isLastPage;
                res.lastEvaluatedKey = r.lastEvaluatedKey;
                res.count += r.count;
                res.hasMore = r.hasMore;
                r.items.forEach(function(item){
                    res.items.push(item);
                });
                return getNextPage(res, callback);
            });
        }
        else{
            debug('Got all pages.  Resolving');
            callback(null, res);
        }
    }
{'fraction_non_alphanumeric': 0.1928725279028784, 'fraction_numerical': 0.007440767573918152, 'mean_word_length': 1.8940509915014165, 'pattern_counts': {'":': 0, '<': 5, '<?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': '854539', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1627, 'n_words': 317}