<commit_before>/* ========================================================================
 * DBH-PG: utilities for creating SQL chunks.
 * ========================================================================
 * Copyright 2014 Sapienlab, <NAME> and Contributors.
 * Licensed under MIT LICENSE (See LICENSE)
 * ======================================================================== */
'use strict';

exports.orderBy = function orderBy(sort) {
    if (!(sort instanceof Array)) {
        sort = sort.orderBy || sort.sort;
    }
    if (!sort || sort.length === 0) {
        return ' ';
    }
    var sql = ' ORDER BY ';
    
    sort.forEach(function(sortRule) {
        sql += sortRule.attr
            + ' '
            + (sortRule.asc !== undefined && !sortRule.asc ? 'DESC' : 'ASC')
            + ', ';
    });
    return sql.slice(0, -2) + ' ';
}

exports.limit = function limit(limit, offset) {
    if (typeof limit === 'object') {
        offset = limit.offset;
        limit = limit.limit;
    }
    if ((offset === undefined || offset === null)
        && (limit === undefined || limit === null)) {
        return ' ';
    } else if (offset === undefined || offset === null) {
        return ' LIMIT ' + parseInt(limit, 10) + ' ';
    } else {
        return ' LIMIT ' + parseInt(limit, 10) +
            ' OFFSET ' + parseInt(offset, 10) + ' ';
    }
}

exports.toNamed = function toNamed(object, separator, inSeparator) {
    separator = separator || 'AND';
    inSeparator = inSeparator || '=';
    var buffer = '';
    for (var key in object) {
        if (object.hasOwnProperty(key)) {
            buffer += ' '
                + key
                + inSeparator<commit_msg>Update sql.js<commit_after>/* ========================================================================
 * DBH-PG: utilities for creating SQL chunks.
 * ========================================================================
 * Copyright 2014 Sapienlab, <NAME> and Contributors.
 * Licensed under MIT LICENSE (See LICENSE)
 * ======================================================================== */
'use strict';

exports.orderBy = function orderBy(sort) {
    if (!(sort instanceof Array)) {
        sort = sort.orderBy || sort.sort;
    }
    if (!sort || sort.length === 0) {
        return ' ';
    }
    var sql = ' ORDER BY ';
    
    sort.forEach(function(sortRule) {
        sql += sortRule.attr
            + ' '
            + (sortRule.asc !== undefined && !sortRule.asc ? 'DESC' : 'ASC')
            + ', ';
    });
    return sql.slice(0, -2) + ' ';
}

exports.limit = function limit(limit, offset) {
    if (!limit) {
        return ' ';
    }
    if (typeof limit === 'object') {
        limit = limit.limit;
        offset = limit.offset;
    }
    limit = parseInt(limit, 10);
    offset = parseInt(offset, 10);
    if (isNaN(limit) || limit < 0) {
        return ' ';
    } else if (isNaN(offset) || offset < 0) {
        return ' LIMIT ' + limit + ' ';
    } else {
        return ' LIMIT ' + limit + ' OFFSET ' + offset + ' ';
    }
}

exports.toNamed = function toNamed(object, separator, inSeparator) {
    separator = separator || 'AND';
    inSeparator = inSeparator || '=';
    var buffer = '';
    for (var key in object) {
        if (object.hasOwnProperty(key)) {
            buffer += ' '
                + key
                + inSeparator
{'fraction_non_alphanumeric': 0.2662704309063893, 'fraction_numerical': 0.007726597325408618, 'mean_word_length': 2.417258883248731, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1483441', 'n_tokens_mistral': 967, 'n_tokens_neox': 919, 'n_words': 226}