Fix format, logging

master
Vitaliy Filippov 2020-04-29 19:02:53 +03:00
parent e4a271d6bd
commit 0db2ddd579
1 changed files with 14 additions and 7 deletions

View File

@ -1,6 +1,6 @@
// Простенький "селект билдер" по мотивам MediaWiki-овского, успешно юзаю подобный в PHP уже лет 8
// (c) Виталий Филиппов, 2019
// Версия 2020-01-06
// (c) Виталий Филиппов, 2019-2020
// Версия 2020-03-25
// В PHP, правда, прикольнее - там в массиве можно смешивать строковые и численные ключи,
// благодаря чему можно писать $where = [ 't1.a=t2.a', 't2.b' => [ 1, 2, 3 ] ]
@ -409,14 +409,14 @@ async function select(dbh, tables, fields, where, options, format)
data.rows.forEach(r => delete r['*']);
}
}
if ((format & MS_LIST) || (format & MS_COL))
if (format & MS_LIST)
data = data.rows.map(r => Object.values(r));
else if (format & MS_COL)
data = data.rows.map(r => Object.values(r)[0]);
else
data = data.rows;
if (format & MS_ROW)
data = data[0];
if (data && (format & MS_COL))
data = data[0];
return calc_found_rows ? [ found_rows, data ] : data;
}
@ -734,15 +734,22 @@ class Connection extends ConnectionBase
}
this.connection_lost = false;
sql = (bind && bind.length ? _inline(sql, bind) : sql);
if (this.config.log_queries)
console.log('> '+sql);
let start_time;
try
{
if (!this.in_transaction)
{
this.in_transaction = true;
}
if (this.config.log_queries)
{
start_time = Date.now();
}
const r = await this.dbh.query(sql);
if (this.config.log_queries)
{
console.log('> pid='+process.pid+' '+((Date.now()-start_time)/1000).toFixed(3)+' '+sql);
}
if (this.in_transaction === true)
{
this.in_transaction = false;