<commit_before>(function(window, owl) {
    function Model(data, options){
        this.data = data || {};
        this.baseUrl = options.baseUrl || '';
        this.idField = options.idField || 'id';
    }
    Model.prototype.get = function(name) {
        return this.data[name];
    };
    Model.prototype.set = function(name, value) {
        this.data[name] = value;
    };
    /**
     * Gets data from the sever
     * @param query
     * @return Promise
     */
    Model.prototype.fetch = function(query) {
        var that = this;
        return owl.ajax({
            url: this.baseUrl + '/' + this.data[this.idField] + owl.ajax.toQueryString(query),
            type: 'GET'
        })
        .then(function(result) {
            that.data = result;
            return result;
        });
    };
    /**
     * Removes all attributes from the model
     */
    Model.prototype.clear = function() {
        this.data = {};
    };
    /**
     * Save a model to database
     * @param query
     * @return Promise
     */
    Model.prototype.save = function(query) {
        var that = this;
        var url  = this.baseUrl;
        var id = this.data[this.idField];
        if(id) {
            url += '/' + this.data[this.idField];
        }
        return owl.ajax({
            url: url + owl.ajax.toQueryString(query),
            type: id ? 'PUT' : 'POST',
            data: this.data
        })
        .then(function(result) {
            if(result[that.idField]) {
                that.data[that.idField] = result[that.idField];
            }
            return result;
        });
    };
    /**
     * Remove a model
     * @param query
     * @return Promise
     */
    Model.prototype.destroy = function(query) {
        var that = this;
        return owl.ajax({
            url: this.baseUrl + '/' + this.data.id + owl.ajax.toQueryString(query),
            type: 'DELETE'
        })
        .then(function(result) {
            that.clear();
            return result;
        });
    };
    /**
     * Gets data
     * @return
     */
    Model.prototype.getData = function() {
        return this.data;<commit_msg>Add update and patch methods to model.<commit_after>(function(window, owl) {
    function Model(data, options){
        this.data = data || {};
        this.baseUrl = options.baseUrl || '';
        this.idField = options.idField || 'id';
    }
    Model.prototype.get = function(name) {
        return this.data[name];
    };
    Model.prototype.set = function(name, value) {
        this.data[name] = value;
    };
    /**
     * Gets data from the sever
     * @param query
     * @return Promise
     */
    Model.prototype.fetch = function(query) {
        var that = this;
        return owl.ajax({
            url: this.baseUrl + '/' + this.data[this.idField] + owl.ajax.toQueryString(query),
            type: 'GET'
        })
        .then(function(result) {
            that.data = result;
            return result;
        });
    };
    /**
     * Removes all attributes from the model
     */
    Model.prototype.clear = function() {
        this.data = {};
    };
    /**
     * Save a model to database
     * @param query
     * @return Promise
     */
    Model.prototype.save = function(query) {
        var that = this;
        var url  = this.baseUrl;
        var id = this.data[this.idField];
        if(id) {
            url += '/' + this.data[this.idField];
        }
        return owl.ajax({
            url: url + owl.ajax.toQueryString(query),
            type: id ? 'PUT' : 'POST',
            data: this.data
        })
        .then(function(result) {
            if(result[that.idField]) {
                that.data[that.idField] = result[that.idField];
            }
            return result;
        });
    };
    /**
     * Updates local data and saves model
     * @param data
     * @param query
     * @return Promise
     */
    Model.prototype.update = function(data, query) {
        this.data = owl.util.extend(this.data, data);
        this.save(query);
    };
    /**
     * Partially updates model
     * @param data
     * @param query
     * @return Promise
     */
    Model.prototype.patch = function(data, query) {
        var that = this;
        var id = this.data[this.idField];
        var url  = this.baseUrl + '/' + id;
        if(!id) {
            return new Promise(function(resolve, reject) {
                reject('Can not patch model without id');
            });
        }

        this.data = owl.util.extend(this.data, data);

        return owl.ajax({
                url: url + owl.ajax.toQueryString(query),
                type: 'PATCH',
                data: data
            })
            .then(function(result) {
                if(result[that.idField]) {
                    that.data[that.idField] = result[that.idField];
                }
                return result;
            });
    };
    /**
     * Remove a model
     * @param query
     * @return Promise
     */
    Model.prototype.destroy = function(query) {
        var that = this;
        return owl.ajax({
            url: this.baseUrl + '/' + this.data.id + owl.ajax.toQueryString(query),
            type: 'DELETE'
        })
        .then(function(result) {
            that.clear();
            return result;
        });
    };
    /**
     * Gets data
     * @return
     */
    Model.prototype.getData = function() {
        return this.data;
{'fraction_non_alphanumeric': 0.13665624425234504, 'fraction_numerical': 0.0, 'mean_word_length': 1.4842393787117405, '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': '6671305', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1589, 'n_words': 331}