DB driver changed to mysql to address issue #509.
This commit is contained in:
parent
2e847460f4
commit
de55870561
7 changed files with 168 additions and 254 deletions
|
@ -5,7 +5,7 @@ This module handles Mailtrain database initialization and upgrades
|
|||
*/
|
||||
|
||||
const config = require('config');
|
||||
const mysql = require('mysql2');
|
||||
const mysql = require('mysql');
|
||||
const log = require('./log');
|
||||
const fs = require('fs');
|
||||
const pathlib = require('path');
|
||||
|
|
|
@ -28,9 +28,10 @@ async function ajaxListTx(tx, params, queryFun, columns, options) {
|
|||
const query = queryFun(tx);
|
||||
query.whereIn(columnsNames[parseInt(params.column)], params.values);
|
||||
query.select(columnsSelect);
|
||||
query.options({rowsAsArray:true});
|
||||
query.options({nestTables: '.'});
|
||||
|
||||
const rows = await query;
|
||||
|
||||
const rowsOfArray = rows.map(row => Object.keys(row).map(key => row[key]));
|
||||
return rowsOfArray;
|
||||
|
||||
|
@ -78,9 +79,13 @@ async function ajaxListTx(tx, params, queryFun, columns, options) {
|
|||
}
|
||||
}
|
||||
|
||||
query.options({rowsAsArray:true});
|
||||
query.options({nestTables: '.'});
|
||||
|
||||
const rows = await query;
|
||||
|
||||
// Here we rely on the fact that Object.keys(row) returns the columns in the same order as they are given in the select (i.e. in columnsNames).
|
||||
// This should work because ES2015 guarantees chronological order of keys in an object and mysql (https://github.com/mysqljs/mysql/blob/ad014c82b2cbaf47acae1cc39e5533d3cb6eb882/lib/protocol/packets/RowDataPacket.js#L43)
|
||||
// adds them in the order of select columns.
|
||||
const rowsOfArray = rows.map(row => {
|
||||
const arr = Object.keys(row).map(field => row[field]);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ const config = require('config');
|
|||
const moment = require('moment');
|
||||
|
||||
const knex = require('knex')({
|
||||
client: 'mysql2',
|
||||
client: 'mysql',
|
||||
connection: {
|
||||
...config.mysql,
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue