<commit_before>
// model
var Data = {

    // send model request
    req: function (query, data, callback) {
        var self = this;

        // emit server event
        self._.emit('Q>', {
            m: self._name,
            q: query,
            d: data
        }, function (err, data) {

            // save current data
            self.data = data;

            // callback
            callback(err, data);
        });
    }
};

// model
// TODO add an option for live updates (push)
// TODO update a connected view on live update
function factory (model, config) {
    var self = this;

    model._ = self;
    model.data = [{}];

    // save flat schema in models cache
    model.schema = self._flat(config);

    // save model in instance
    self.model[config.name] = model;
}<commit_msg>moved fetch method to the data module<commit_after>
// model
var Data = {

    // send model request
    req: function (query, data, callback) {
        var self = this;

        // emit server event
        self._.emit('Q>', {
            m: self._name,
            q: query,
            d: data
        }, function (err, data) {

            // save current data
            self.data = data;

            // callback
            callback(err, data);
        });
    }
};

// model
// TODO add an option for live updates (push)
// TODO update a connected view on live update
function factory (model, config) {
    var self = this;

    model._ = self;
    model.data = [{}];

    // save flat schema in models cache
    model.schema = self._flat(config);

    // save model in instance
    self.model[config.name] = model;
}


function fetch (event, data, callback) {
    var self = this;
    var model = data.model;
    var query = data.query;
    data = data.data;

    if (!model || !query) {
        return callback('No model or query.');
    }

    if (!self.model || !self.model[model]) {
        return callback('Model not found.');
    }

    self.model[model].req(query, data, function (err, data) {

        if (err) {
            return callback(err);
        }

        // emit callback event
        callback(null, {data: data});
    });
}
{'fraction_non_alphanumeric': 0.1266233766233766, 'fraction_numerical': 0.0, 'mean_word_length': 1.6895261845386533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4467833', 'n_tokens_mistral': 628, 'n_tokens_neox': 610, 'n_words': 206}