ms sql analyser class, typescript check

This commit is contained in:
Jan Prochazka
2020-01-06 22:33:20 +01:00
parent b31bf2b5d0
commit c886846268
11 changed files with 80 additions and 2 deletions

View File

@@ -18,9 +18,11 @@
"socket.io": "^2.3.0"
},
"scripts": {
"start": "nodemon src/index.js"
"start": "nodemon src/index.js",
"tscheck": "tsc --allowJs --noEmit src/index.js"
},
"devDependencies": {
"nodemon": "^2.0.2"
"nodemon": "^2.0.2",
"typescript": "^3.7.4"
}
}

View File

@@ -1,5 +1,8 @@
// @ts-check
const path = require('path');
const { fork } = require('child_process');
// @ts-ignore
const _ = require('lodash');
const nedb = require('nedb-promises');
@@ -12,6 +15,7 @@ module.exports = {
async _init() {
const dir = await datadir();
// @ts-ignore
this.datastore = nedb.create(path.join(dir, 'connections.jsonl'));
},

View File

@@ -0,0 +1,15 @@
// @ts-check
class DatabaseAnalyser {
/**
*
* @param {import('../default/types').EngineDriver} driver
*/
constructor(pool, driver) {
this.pool = pool;
this.driver = driver;
}
runAnalysis() {}
}
module.exports = DatabaseAnalyser;

View File

@@ -0,0 +1,8 @@
export interface EngineDriver {
connect({ server, port, user, password });
query(pool, sql: string): [];
getVersion(pool): string;
listDatabases(pool): [{ name: string }];
analyseFull(pool);
analyseIncremental(pool);
}

View File

@@ -0,0 +1,22 @@
// @ts-check
const fs = require('fs-extra');
const path = require('path');
const DatabaseAnalayser = require('../default/DatabaseAnalyser');
async function loadQuery(name) {
return await fs.readFile(path.join(__dirname, name), 'utf-8');
}
class MsSqlAnalyser extends DatabaseAnalayser {
constructor(pool, driver) {
super(pool, driver);
}
async runAnalysis() {
const tables = this.driver.query(this.pool, await loadQuery('tables.sql'));
}
}
module.exports = MsSqlAnalyser;

View File

@@ -17,4 +17,10 @@ module.exports = {
const res = await this.query(pool, 'SELECT name FROM sys.databases order by name');
return res;
},
async analyseFull(pool) {
},
async analyseIncremental(pool) {
},
};

View File

@@ -0,0 +1,6 @@
select
o.name as tableName, s.name as schemaName, o.objectId,
o.createDate, o.modifyDate
from sys.tables o
inner join sys.schemas s on o.schema_id = s.schema_id
where o.object_id =[OBJECT_ID_CONDITION]

View File

@@ -1,3 +1,5 @@
// @ts-check
const os = require('os');
const path = require('path');
const fs = require('fs-extra');

View File

@@ -1,3 +1,5 @@
// @ts-check
let socket = null;
module.exports = {

View File

@@ -1,6 +1,12 @@
// @ts-check
// @ts-ignore
const _ = require('lodash');
const express = require('express');
/**
* @param {string} route
*/
module.exports = function useController(app, route, controller) {
const router = express.Router();

View File

@@ -2561,6 +2561,11 @@ type-is@~1.6.17, type-is@~1.6.18:
media-typer "0.3.0"
mime-types "~2.1.24"
typescript@^3.7.4:
version "3.7.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.4.tgz#1743a5ec5fef6a1fa9f3e4708e33c81c73876c19"
integrity sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==
undefsafe@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/undefsafe/-/undefsafe-2.0.2.tgz#225f6b9e0337663e0d8e7cfd686fc2836ccace76"