<commit_before>/*global require, module */

const config = require('/etc/xray/config.json');
const pg = require('pg');
const logger = require('./logger.js');

const db_cfg = config.scraper.db;
db_cfg.max = 10;
db_cfg.idleTimeoutMillis = 30000;

//this initializes a connection pool
//it will keep idle connections open for 30 seconds
//and set a limit of maximum 10 idle clients
const pool = new pg.Pool(db_cfg);

pool.on('error', function(err) {
    logger.err('idle client error '+ err.message + err.stack);
});

//export the query method for passing queries to the pool
function query(text, values) {
    logger.debug('query:'+ text+ values);
    return pool.query(text, values);
}

// the pool also supports checking out a client for
// multiple operations, such as a transaction
function connect() {
    return pool.connect();
}

async function insertDev(dev) {
    var res = await query('SELECT id FROM developers WHERE $1 = ANY(email)', [dev.email]);
    if (res.rowCount > 0) {
        return res.rows[0].id;
    }

    // maybe dev id needs to be URL encoded?
    let store_site = 'https://play.google.com/store/apps/developer?id=' + dev.id;
    res = await query('INSERT INTO developers(email,name,store_site,site) VALUES ($1, $2, $3, $4) RETURNING id', [
        [dev.email], dev.name, store_site, dev.site
    ]);
    return res.rows[0].id;
}

module.exports = {
    insertPlayApp: async(app, region) => {<commit_msg>update db.js to use old logging format<commit_after>'use strict';
/*global require, module */

const config = require('/etc/xray/config.json');
const pg = require('pg');
const logger = require('./logger.js');

const db_cfg = config.scraper.db;
db_cfg.max = 10;
db_cfg.idleTimeoutMillis = 30000;

//this initializes a connection pool
//it will keep idle connections open for 30 seconds
//and set a limit of maximum 10 idle clients
const pool = new pg.Pool(db_cfg);

pool.on('error', function(err) {
    logger.err('idle client error', err.message, err.stack);
});

//export the query method for passing queries to the pool
function query(text, values) {
    logger.debug('query:', text, values);
    return pool.query(text, values);
}

// the pool also supports checking out a client for
// multiple operations, such as a transaction
function connect() {
    return pool.connect();
}

async function insertDev(dev) {
    var res = await query('SELECT id FROM developers WHERE $1 = ANY(email)', [dev.email]);
    if (res.rowCount > 0) {
        return res.rows[0].id;
    }

    // maybe dev id needs to be URL encoded?
    let store_site = 'https://play.google.com/store/apps/developer?id=' + dev.id;
    res = await query('INSERT INTO developers(email,name,store_site,site) VALUES ($1, $2, $3, $4) RETURNING id', [
        [dev.email], dev.name, store_site, dev.site
    ]);
    return res.rows[0].id;
}

module.exports = {
    insertPlayApp: async(app, region) => {
{'fraction_non_alphanumeric': 0.14162348877374784, 'fraction_numerical': 0.013126079447322971, 'mean_word_length': 3.641025641025641, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '79497', 'n_tokens_mistral': 926, 'n_tokens_neox': 900, 'n_words': 296}