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