mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 19:36:00 +00:00
native module refactor POC
This commit is contained in:
@@ -31,12 +31,17 @@
|
|||||||
"plugout": "dbgate-plugout dbgate-plugin-mssql"
|
"plugout": "dbgate-plugout dbgate-plugin-mssql"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"webpack": "^5.91.0",
|
||||||
|
"webpack-cli": "^5.1.4"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
"async-lock": "^1.2.6",
|
"async-lock": "^1.2.6",
|
||||||
"dbgate-plugin-tools": "^1.0.7",
|
"dbgate-plugin-tools": "^1.0.7",
|
||||||
"dbgate-query-splitter": "^4.11.2",
|
"dbgate-query-splitter": "^4.11.2",
|
||||||
"dbgate-tools": "^5.0.0-alpha.1",
|
"dbgate-tools": "^5.0.0-alpha.1",
|
||||||
"tedious": "^18.2.0",
|
"tedious": "^18.2.0"
|
||||||
"webpack": "^5.91.0",
|
},
|
||||||
"webpack-cli": "^5.1.4"
|
"optionalDependencies": {
|
||||||
|
"msnodesqlv8": "^4.2.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,13 @@ const MsSqlAnalyser = require('./MsSqlAnalyser');
|
|||||||
const createTediousBulkInsertStream = require('./createTediousBulkInsertStream');
|
const createTediousBulkInsertStream = require('./createTediousBulkInsertStream');
|
||||||
const createNativeBulkInsertStream = require('./createNativeBulkInsertStream');
|
const createNativeBulkInsertStream = require('./createNativeBulkInsertStream');
|
||||||
const AsyncLock = require('async-lock');
|
const AsyncLock = require('async-lock');
|
||||||
const nativeDriver = require('./nativeDriver');
|
|
||||||
const lock = new AsyncLock();
|
const lock = new AsyncLock();
|
||||||
const { tediousConnect, tediousQueryCore, tediousReadQuery, tediousStream } = require('./tediousDriver');
|
const { tediousConnect, tediousQueryCore, tediousReadQuery, tediousStream } = require('./tediousDriver');
|
||||||
const { nativeConnect, nativeQueryCore, nativeReadQuery, nativeStream } = nativeDriver;
|
const { nativeConnect, nativeQueryCore, nativeReadQuery, nativeStream } = require('./nativeDriver');
|
||||||
const { getLogger } = global.DBGATE_PACKAGES['dbgate-tools'];
|
const { getLogger } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||||
|
|
||||||
const logger = getLogger('mssqlDriver');
|
const logger = getLogger('mssqlDriver');
|
||||||
|
|
||||||
let requireMsnodesqlv8;
|
|
||||||
let platformInfo;
|
let platformInfo;
|
||||||
let authProxy;
|
let authProxy;
|
||||||
|
|
||||||
@@ -59,7 +57,7 @@ const driver = {
|
|||||||
|
|
||||||
getAuthTypes() {
|
getAuthTypes() {
|
||||||
const res = [];
|
const res = [];
|
||||||
if (requireMsnodesqlv8) res.push(...windowsAuthTypes);
|
if (platformInfo?.isWindows) res.push(...windowsAuthTypes);
|
||||||
|
|
||||||
if (authProxy.isAuthProxySupported()) {
|
if (authProxy.isAuthProxySupported()) {
|
||||||
res.push(
|
res.push(
|
||||||
@@ -82,7 +80,7 @@ const driver = {
|
|||||||
|
|
||||||
async connect(conn) {
|
async connect(conn) {
|
||||||
const { authType } = conn;
|
const { authType } = conn;
|
||||||
const connectionType = requireMsnodesqlv8 && (authType == 'sspi' || authType == 'sql') ? 'msnodesqlv8' : 'tedious';
|
const connectionType = platformInfo?.isWindows && (authType == 'sspi' || authType == 'sql') ? 'msnodesqlv8' : 'tedious';
|
||||||
const client = connectionType == 'msnodesqlv8' ? await nativeConnect(conn) : await tediousConnect(conn);
|
const client = connectionType == 'msnodesqlv8' ? await nativeConnect(conn) : await tediousConnect(conn);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -172,12 +170,8 @@ const driver = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
driver.initialize = dbgateEnv => {
|
driver.initialize = dbgateEnv => {
|
||||||
if (dbgateEnv.nativeModules && dbgateEnv.nativeModules.msnodesqlv8) {
|
|
||||||
requireMsnodesqlv8 = dbgateEnv.nativeModules.msnodesqlv8;
|
|
||||||
}
|
|
||||||
platformInfo = dbgateEnv.platformInfo;
|
platformInfo = dbgateEnv.platformInfo;
|
||||||
authProxy = dbgateEnv.authProxy;
|
authProxy = dbgateEnv.authProxy;
|
||||||
nativeDriver.initialize(dbgateEnv);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = driver;
|
module.exports = driver;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const stream = require('stream');
|
const stream = require('stream');
|
||||||
const makeUniqueColumnNames = require('./makeUniqueColumnNames');
|
const makeUniqueColumnNames = require('./makeUniqueColumnNames');
|
||||||
let requireMsnodesqlv8;
|
|
||||||
const { extractDbNameFromComposite } = global.DBGATE_PACKAGES['dbgate-tools'];
|
const { extractDbNameFromComposite } = global.DBGATE_PACKAGES['dbgate-tools'];
|
||||||
|
|
||||||
// async function nativeQueryCore(pool, sql, options) {
|
// async function nativeQueryCore(pool, sql, options) {
|
||||||
@@ -24,7 +23,7 @@ const { extractDbNameFromComposite } = global.DBGATE_PACKAGES['dbgate-tools'];
|
|||||||
let msnodesqlv8Value;
|
let msnodesqlv8Value;
|
||||||
function getMsnodesqlv8() {
|
function getMsnodesqlv8() {
|
||||||
if (!msnodesqlv8Value) {
|
if (!msnodesqlv8Value) {
|
||||||
msnodesqlv8Value = requireMsnodesqlv8();
|
msnodesqlv8Value = require('msnodesqlv8');
|
||||||
}
|
}
|
||||||
return msnodesqlv8Value;
|
return msnodesqlv8Value;
|
||||||
}
|
}
|
||||||
@@ -225,16 +224,9 @@ async function nativeStream(dbhan, sql, options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialize = dbgateEnv => {
|
|
||||||
if (dbgateEnv.nativeModules && dbgateEnv.nativeModules.msnodesqlv8) {
|
|
||||||
requireMsnodesqlv8 = dbgateEnv.nativeModules.msnodesqlv8;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
nativeConnect,
|
nativeConnect,
|
||||||
nativeQueryCore,
|
nativeQueryCore,
|
||||||
nativeReadQuery,
|
nativeReadQuery,
|
||||||
nativeStream,
|
nativeStream,
|
||||||
initialize,
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ var config = {
|
|||||||
// optimization: {
|
// optimization: {
|
||||||
// minimize: false,
|
// minimize: false,
|
||||||
// },
|
// },
|
||||||
|
|
||||||
|
externals: {
|
||||||
|
msnodesqlv8: 'commonjs msnodesqlv8',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = config;
|
module.exports = config;
|
||||||
|
|||||||
Reference in New Issue
Block a user