<commit_before>'use strict';

const COLUMNS = ['app_name', 'strategies'];
const TABLE = 'client_strategies';

module.exports = function (db) {
    function update (appName, strategies) {
        return db(TABLE)
            .where('app_name', appName)  // eslint-disable-line
            .update({
                strategies: JSON.stringify(strategies),
                updated_at: 'now()', // eslint-disable-line
            });
    }

    function insert (appName, strategies) {
        return db(TABLE).insert({
            app_name: appName,  // eslint-disable-line
            strategies: JSON.stringify(strategies),
        });
    }

    function insertOrUpdate (appName, strategies) {
        return db(TABLE)
            .count('*')
            .where('app_name', appName)
            .map(row => ({ count: row.count }))
            .then(rows => {
                return rows[0].count > 0 ? update(appName, strategies) : insert(appName, strategies);
            });
    }

    function getAll () {
        return db
            .select(COLUMNS)
            .from(TABLE)
            .map(mapRow);
    }

    function mapRow (row) {
        return {
            appName: row.app_name,
            strategies: row.strategies,
        };
    }

    return { insertOrUpdate, getAll };
};<commit_msg>fix lint<commit_after>'use strict';

const COLUMNS = ['app_name', 'strategies'];
const TABLE = 'client_strategies';

module.exports = function (db) {
    function update (appName, strategies) {
        return db(TABLE)
            .where('app_name', appName)  // eslint-disable-line
            .update({
                strategies: JSON.stringify(strategies),
                updated_at: 'now()', // eslint-disable-line
            });
    }

    function insert (appName, strategies) {
        return db(TABLE).insert({
            app_name: appName,  // eslint-disable-line
            strategies: JSON.stringify(strategies),
        });
    }

    function insertOrUpdate (appName, strategies) {
        return db(TABLE)
            .count('*')
            .where('app_name', appName)
            .map(row => ({ count: row.count }))
            .then(rows => {
                if (rows[0].count > 0) {
                    return update(appName, strategies);
                } else {
                    return insert(appName, strategies);
                }
            });
    }

    function getAll () {
        return db
            .select(COLUMNS)
            .from(TABLE)
            .map(mapRow);
    }

    function mapRow (row) {
        return {
            appName: row.app_name,
            strategies: row.strategies,
        };
    }

    return { insertOrUpdate, getAll };
};
{'fraction_non_alphanumeric': 0.12791991101223582, 'fraction_numerical': 0.0014831294030404152, 'mean_word_length': 1.6219630709426627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6432387', 'n_tokens_mistral': 776, 'n_tokens_neox': 765, 'n_words': 156}