backend bundle refactor

This commit is contained in:
Jan Prochazka
2020-03-14 10:38:10 +01:00
parent cd58555409
commit 1d63908328
15 changed files with 66 additions and 53 deletions

View File

@@ -1,15 +1,8 @@
const fp = require("lodash/fp");
const _ = require("lodash");
const fp = require('lodash/fp');
const _ = require('lodash');
const sql = require('./sql');
const DatabaseAnalayser = require("../default/DatabaseAnalyser");
/** @returns {Promise<string>} */
async function loadQuery(pool, name) {
return await pool._nativeModules.fs.readFile(
pool._nativeModules.path.join(__dirname, name),
"utf-8"
);
}
const DatabaseAnalayser = require('../default/DatabaseAnalyser');
class MySqlAnalyser extends DatabaseAnalayser {
constructor(pool, driver) {
@@ -24,20 +17,14 @@ class MySqlAnalyser extends DatabaseAnalayser {
functions = false,
triggers = false
) {
let res = await loadQuery(this.pool, resFileName);
res = res.replace("=[OBJECT_NAME_CONDITION]", " is not null");
res = res.replace("#DATABASE#", this.pool._database_name);
let res = sql[resFileName];
res = res.replace('=[OBJECT_NAME_CONDITION]', ' is not null');
res = res.replace('#DATABASE#', this.pool._database_name);
return res;
}
async runAnalysis() {
const tables = await this.driver.query(
this.pool,
await this.createQuery("tables.sql")
);
const columns = await this.driver.query(
this.pool,
await this.createQuery("columns.sql")
);
const tables = await this.driver.query(this.pool, await this.createQuery('tables'));
const columns = await this.driver.query(this.pool, await this.createQuery('columns'));
// const pkColumns = await this.driver.query(this.pool, await this.createQuery('primary_keys.sql'));
// const fkColumns = await this.driver.query(this.pool, await this.createQuery('foreign_keys.sql'));
@@ -48,9 +35,9 @@ class MySqlAnalyser extends DatabaseAnalayser {
.map(({ isNullable, extra, ...col }) => ({
...col,
notNull: !isNullable,
autoIncrement: extra && extra.toLowerCase().includes("auto_increment")
autoIncrement: extra && extra.toLowerCase().includes('auto_increment'),
})),
foreignKeys: []
foreignKeys: [],
// primaryKey: extractPrimaryKeys(table, pkColumns.rows),
// foreignKeys: extractForeignKeys(table, fkColumns.rows),
}));

View File

@@ -1,3 +1,4 @@
module.exports = `
select
TABLE_NAME as pureName,
COLUMN_NAME as columnName,
@@ -11,3 +12,4 @@ select
from INFORMATION_SCHEMA.COLUMNS
where TABLE_SCHEMA = '#DATABASE#' and TABLE_NAME =[OBJECT_NAME_CONDITION]
order by ORDINAL_POSITION
`;

View File

@@ -0,0 +1,7 @@
const columns = require('./columns');
const tables = require('./tables');
module.exports = {
columns,
tables,
};

View File

@@ -1,5 +1,7 @@
module.exports = `
select
TABLE_NAME as pureName,
case when ENGINE='InnoDB' then CREATE_TIME else coalesce(UPDATE_TIME, CREATE_TIME) end as alterTime
from information_schema.tables
where TABLE_SCHEMA = '#DATABASE#' and TABLE_NAME =[OBJECT_NAME_CONDITION];
`;