mirror of
https://github.com/dbgate/dbgate
synced 2024-11-08 12:47:25 +00:00
43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
const fp = require('lodash/fp');
|
|
const _ = require('lodash');
|
|
const sql = require('./sql');
|
|
|
|
const DatabaseAnalayser = require('../default/DatabaseAnalyser');
|
|
|
|
class MySqlAnalyser extends DatabaseAnalayser {
|
|
constructor(pool, driver) {
|
|
super(pool, driver);
|
|
}
|
|
|
|
createQuery(resFileName, tables = false, views = false, procedures = false, functions = false, triggers = false) {
|
|
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, this.createQuery('tables'));
|
|
const columns = await this.driver.query(this.pool, this.createQuery('columns'));
|
|
// const pkColumns = await this.driver.query(this.pool, this.createQuery('primary_keys.sql'));
|
|
// const fkColumns = await this.driver.query(this.pool, this.createQuery('foreign_keys.sql'));
|
|
|
|
return this.mergeAnalyseResult({
|
|
tables: tables.rows.map((table) => ({
|
|
...table,
|
|
columns: columns.rows
|
|
.filter((col) => col.pureName == table.pureName)
|
|
.map(({ isNullable, extra, ...col }) => ({
|
|
...col,
|
|
notNull: !isNullable,
|
|
autoIncrement: extra && extra.toLowerCase().includes('auto_increment'),
|
|
})),
|
|
foreignKeys: [],
|
|
// primaryKey: extractPrimaryKeys(table, pkColumns.rows),
|
|
// foreignKeys: extractForeignKeys(table, fkColumns.rows),
|
|
})),
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = MySqlAnalyser;
|