<commit_before>'use strict';

class SQLString {
  constructor(query, ...args) {
    this.query = query == null ? '' : query.toString();
    this.args = args;
  }

  escape(obj, quote, name, format='$&') {
    let type = typeof obj;
    if (obj == null) {
      return 'NULL';
    }
    if (type === 'number' || type === 'boolean') {
      obj = +obj;
    }
    if (type !== 'object') {
      return this.escapeString(obj.toString(), quote);
    }
    if (obj instanceof SQLString) {
      let res = `(${obj})`;
      if (name != null && quote === '`') {
        res += ' AS ' + name;
      }
      return res;
    }
    if (obj instanceof Date) {
      return this.escapeDate(obj);
    }
    if (Array.isArray(obj)) {
      return this.escapeArray(obj, quote).replace(/.*/, format);
    }
    return this.escapeObject(obj, quote).replace(/.*/, format);
  }

  escapeString(str, quote="'") {
    let map = {
      '\0': '\\0',
      '\b': '\\b',
      '\t': '\\t',
      '\n': '\\n',
      '\r': '\\r',
      '\x1a': '\\Z',
      '"': '\\"',
      "'": "\\'",
      '`': '\\`',
      '\\': '\\\\',
    };
    let re = new RegExp('[' + Object.keys(map).map(c => {
      return '\\x' + ('0' + c.charCodeAt(0).toString(16)).slice(-2);
    }).join('') + ']', 'g');
    return quote + str.replace(re, c => map[c]) + quote;
  }

  escapeArray(arr, quote="'", separator=', ') {
    return arr.map(e => this.escape(e, quote, null, '($&)')).join(separator);
  }

  escapeObject(obj, quote="'", separator=', ') {
    return Object.keys(obj).map(key => {
      let k = this.escape(key, '`');
      let v = this.escape(obj[key], quote, null, '($&)');
      if (quote === '`') {
        return `${v} AS ${k}`;
      }
      return `${k} = ${v}`;
    }).join(separator);
  }

  escapeDate(d) {
    let year = ('000' + d.getFullYear()).slice(-4);
    let month = ('0' + (d.getMonth() + 1)).slice(-2);
    let date = ('0' + d.getDate()).slice(-2);
    let hour = ('0' + d.getHours()).slice(-2);
    let minute = ('0' + d.getMinutes()).slice(-2);
    let second = ('0' + d.getSeconds()).slice(-2);
    let msecond = ('00' + d.getMilliseconds()).slice(-3) + '000';
    if (msecond) {
      return `${year}/${month}/${date} ${hour}:${minute}:${second}.${msecond}`;
    }
    return `${year}/${month}/${date} ${hour}:${minute}:${second}`;
  }

  toString() {
    let args = Array.from(this.args);
    return this.query.replace(/(\?\??)|(::?)(\w+)/g, (all, q, c, name) => {
      if (q != null) {
        let arg = args.shift();
        return this.escape(arg, q.length === 1 ? "'" : '`');
      }
      for (let arg of args) {<commit_msg>Fix espace date if not has msec<commit_after>'use strict';

class SQLString {
  constructor(query, ...args) {
    this.query = query == null ? '' : query.toString();
    this.args = args;
  }

  escape(obj, quote, name, format='$&') {
    let type = typeof obj;
    if (obj == null) {
      return 'NULL';
    }
    if (type === 'number' || type === 'boolean') {
      obj = +obj;
    }
    if (type !== 'object') {
      return this.escapeString(obj.toString(), quote);
    }
    if (obj instanceof SQLString) {
      let res = `(${obj})`;
      if (name != null && quote === '`') {
        res += ' AS ' + name;
      }
      return res;
    }
    if (obj instanceof Date) {
      return this.escapeDate(obj);
    }
    if (Array.isArray(obj)) {
      return this.escapeArray(obj, quote).replace(/.*/, format);
    }
    return this.escapeObject(obj, quote).replace(/.*/, format);
  }

  escapeString(str, quote="'") {
    let map = {
      '\0': '\\0',
      '\b': '\\b',
      '\t': '\\t',
      '\n': '\\n',
      '\r': '\\r',
      '\x1a': '\\Z',
      '"': '\\"',
      "'": "\\'",
      '`': '\\`',
      '\\': '\\\\',
    };
    let re = new RegExp('[' + Object.keys(map).map(c => {
      return '\\x' + ('0' + c.charCodeAt(0).toString(16)).slice(-2);
    }).join('') + ']', 'g');
    return quote + str.replace(re, c => map[c]) + quote;
  }

  escapeArray(arr, quote="'", separator=', ') {
    return arr.map(e => this.escape(e, quote, null, '($&)')).join(separator);
  }

  escapeObject(obj, quote="'", separator=', ') {
    return Object.keys(obj).map(key => {
      let k = this.escape(key, '`');
      let v = this.escape(obj[key], quote, null, '($&)');
      if (quote === '`') {
        return `${v} AS ${k}`;
      }
      return `${k} = ${v}`;
    }).join(separator);
  }

  escapeDate(d) {
    let year = ('000' + d.getFullYear()).slice(-4);
    let month = ('0' + (d.getMonth() + 1)).slice(-2);
    let date = ('0' + d.getDate()).slice(-2);
    let hour = ('0' + d.getHours()).slice(-2);
    let minute = ('0' + d.getMinutes()).slice(-2);
    let second = ('0' + d.getSeconds()).slice(-2);
    let msecond = ('00' + d.getMilliseconds()).slice(-3) + '000';
    if (+msecond) {
      return `${year}/${month}/${date} ${hour}:${minute}:${second}.${msecond}`;
    }
    return `${year}/${month}/${date} ${hour}:${minute}:${second}`;
  }

  toString() {
    let args = Array.from(this.args);
    return this.query.replace(/(\?\??)|(::?)(\w+)/g, (all, q, c, name) => {
      if (q != null) {
        let arg = args.shift();
        return this.escape(arg, q.length === 1 ? "'" : '`');
      }
      for (let arg of args) {
{'fraction_non_alphanumeric': 0.2625166571482962, 'fraction_numerical': 0.011422044545973729, 'mean_word_length': 2.253250773993808, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 13, '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': '150429', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1916, 'n_words': 404}