typescript common lib

This commit is contained in:
Jan Prochazka
2020-02-01 19:57:07 +01:00
parent 8291885d56
commit d22058382f
15 changed files with 3434 additions and 94 deletions

View File

@@ -6,7 +6,7 @@ const { fork } = require('child_process');
const DatabaseAnalyser = require('../engines/default/DatabaseAnalyser');
module.exports = {
/** @type {import('../types').OpenedDatabaseConnection[]} */
/** @type {import('@dbgate/lib').OpenedDatabaseConnection[]} */
opened: [],
requests: {},
@@ -48,7 +48,7 @@ module.exports = {
return newOpened;
},
/** @param {import('../types').OpenedDatabaseConnection} conn */
/** @param {import('@dbgate/lib').OpenedDatabaseConnection} conn */
async sendRequest(conn, message) {
const msgid = uuidv1();
const promise = new Promise((resolve, reject) => {

View File

@@ -1,7 +1,7 @@
class DatabaseAnalyser {
/**
*
* @param {import('../../types').EngineDriver} driver
* @param {import('@dbgate/lib').EngineDriver} driver
*/
constructor(pool, driver) {
this.pool = pool;
@@ -11,7 +11,7 @@ class DatabaseAnalyser {
async runAnalysis() {}
}
/** @returns {import('../../types').DatabaseInfo} */
/** @returns {import('@dbgate/lib').DatabaseInfo} */
DatabaseAnalyser.createEmptyStructure = () => ({
tables: [],
});

View File

@@ -1,8 +1,7 @@
/** @return {import('../types').EngineDriver} */
/** @return {import('@dbgate/lib').EngineDriver} */
function getDriver(connection) {
const { engine } = connection;
return require(`./${engine}`);
}
module.exports = getDriver;

View File

@@ -1,33 +0,0 @@
import { ChildProcess } from 'child_process';
export interface QueryResult {
rows: any[];
}
export interface EngineDriver {
connect({ server, port, user, password });
query(pool, sql: string): Promise<QueryResult>;
getVersion(pool): Promise<string>;
listDatabases(pool): Promise<{ name: string }[]>;
analyseFull(pool): Promise<void>;
analyseIncremental(pool): Promise<void>;
}
export interface NamedObjectInfo {
pureName: string;
schemaName: string;
}
export interface TableInfo extends NamedObjectInfo {
}
export interface DatabaseInfo {
tables: TableInfo[];
}
export interface OpenedDatabaseConnection {
conid: string;
database: string;
structure: DatabaseInfo;
subprocess: ChildProcess;
}