Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 deletions packages/driver.mssql/connection.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
]
}
}
},
"ssh": {
"title": "Over SSH",
"type": "string",
"enum": ["Enabled", "Disabled"],
"default": "Disabled"
}
},
"dependencies": {
Expand Down Expand Up @@ -219,9 +225,57 @@
}
}
]
},
"ssh": {
"oneOf": [
{
"properties": {
"ssh": {
"enum": ["Disabled"]
}
}
},
{
"properties": {
"ssh": {
"enum": ["Enabled"]
},
"sshOptions": {
"type": "object",
"title": "SSH Connection Options",
"properties": {
"host": {
"type": "string",
"title": "Server Address",
"minLength": 1
},
"port": {
"type": "integer",
"title": "Port",
"default": 22,
"minimum": 1
},
"username": {
"type": "string",
"title": "Username",
"minLength": 1
},
"password": {
"type": "string",
"title": "Password"
},
"privateKeyPath": {
"type": "string",
"title": "Private Key File Path"
}
},
"required": ["host", "username"]
}
},
"required": ["sshOptions"]
}
]
}
},
"required": [
"connectionMethod"
]
"required": ["connectionMethod"]
}
4 changes: 2 additions & 2 deletions packages/driver.mssql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"build": "cross-env NODE_ENV=production concurrently \"npm:build:*\"",
"build:ext": "yarn run compile:ext --define:process.env.NODE_ENV=\"'production'\" --minify",
"build:ls": "yarn run compile:ls --define:process.env.NODE_ENV=\"'production'\" --minify",
"esbuild": "esbuild --platform=node --tsconfig=./tsconfig.json --external:vscode --color=true --format=cjs",
"esbuild": "esbuild --platform=node --tsconfig=./tsconfig.json --external:vscode --color=true --format=cjs --loader:.node=file",
"prepackage": "yarn run build",
"package": "vsce package --yarn -o .",
"compile:ext": "yarn run esbuild --bundle ./src/extension.ts --outfile=./out/extension.js --target=es2017 --define:process.env.PRODUCT=\"'ext'\"",
Expand All @@ -66,7 +66,7 @@
},
"devDependencies": {
"@sqltools/base-driver": "latest",
"@sqltools/types": "^0.1.7",
"@sqltools/types": "^0.2.0",
"@types/lodash": "^4.14.123",
"@types/mssql": "^4.0.12",
"@types/vscode": "^1.72.0",
Expand Down
57 changes: 42 additions & 15 deletions packages/driver.mssql/src/ls/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,49 @@ export default class MSSQL extends AbstractDriver<MSSQLLib.ConnectionPool, any>
this.credentials.password = null;
}

let pool: MSSQLLib.ConnectionPool;

const pool = new MSSQLLib.ConnectionPool(this.credentials.connectString || {
database: this.credentials.database,
connectionTimeout: this.credentials.connectionTimeout * 1000,
server: this.credentials.server,
user: this.credentials.username,
password: this.credentials.password,
domain: this.credentials.domain || undefined,
port: this.credentials.port,
...mssqlOptions,
options: {
...((mssqlOptions || {}).options || {}),
encrypt: encryptAttempt,
trustServerCertificate: trustServerCertificate,
},
});
if (this.credentials.connectString) {
pool = new MSSQLLib.ConnectionPool(this.credentials.connectString);
} else {
const poolConfig = {
database: this.credentials.database,
connectionTimeout: this.credentials.connectionTimeout * 1000,
server: this.credentials.server,
user: this.credentials.username,
password: this.credentials.password,
domain: this.credentials.domain || undefined,
port: this.credentials.port,
...mssqlOptions,
options: {
...((mssqlOptions || {}).options || {}),
encrypt: encryptAttempt,
trustServerCertificate: trustServerCertificate,
},
};

if (this.credentials.ssh === 'Enabled' && this.credentials.sshOptions) {
const { port: localPort } = await this.createSshTunnel(
{
host: this.credentials.sshOptions.host,
port: this.credentials.sshOptions.port,
username: this.credentials.sshOptions.username,
password: this.credentials.sshOptions.password,
privateKeyPath: this.credentials.sshOptions.privateKeyPath,
},
{
host: this.credentials.server,
port: this.credentials.port,
}
);
Object.assign(poolConfig, {
server: 'localhost',
port: localPort,
});
}

pool = new MSSQLLib.ConnectionPool(poolConfig);
}

await new Promise((resolve, reject) => {
pool.on('error', reject);
Expand Down
17 changes: 15 additions & 2 deletions packages/driver.mssql/ui.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
{
"ui:order": ["connectionMethod", "server", "port", "socketPath", "connectString", "database", "username", "usePassword","password", "mssqlOptions"],
"ui:order": [
"connectionMethod",
"server",
"port",
"socketPath",
"connectString",
"database",
"username",
"usePassword",
"password",
"mssqlOptions",
"ssh",
"sshOptions"
],
"password": { "ui:widget": "password" },
"askForPassword": { "ui:widget": "hidden" },
"socketPath": { "ui:widget": "file" },
Expand All @@ -23,4 +36,4 @@
"ui:help": "The version of TDS to use (default: 7_4, available: 7_1, 7_2, 7_3_A, 7_3_B, 7_4)"
}
}
}
}
60 changes: 57 additions & 3 deletions packages/driver.mysql/connection.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
"title": "Connection Timeout",
"type": "integer",
"minimum": 0
},
"ssh": {
"title": "Over SSH",
"type": "string",
"enum": ["Enabled", "Disabled"],
"default": "Disabled"
}
},
"dependencies": {
Expand Down Expand Up @@ -239,9 +245,57 @@
}
}
]
},
"ssh": {
"oneOf": [
{
"properties": {
"ssh": {
"enum": ["Disabled"]
}
}
},
{
"properties": {
"ssh": {
"enum": ["Enabled"]
},
"sshOptions": {
"type": "object",
"title": "SSH Connection Options",
"properties": {
"host": {
"type": "string",
"title": "Server Address",
"minLength": 1
},
"port": {
"type": "integer",
"title": "Port",
"default": 22,
"minimum": 1
},
"username": {
"type": "string",
"title": "Username",
"minLength": 1
},
"password": {
"type": "string",
"title": "Password"
},
"privateKeyPath": {
"type": "string",
"title": "Private Key File Path"
}
},
"required": ["host", "username"]
}
},
"required": ["sshOptions"]
}
]
}
},
"required": [
"connectionMethod"
]
"required": ["connectionMethod"]
}
4 changes: 2 additions & 2 deletions packages/driver.mysql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"build": "cross-env NODE_ENV=production concurrently \"npm:build:*\"",
"build:ext": "yarn run compile:ext --define:process.env.NODE_ENV=\"'production'\" --minify-whitespace",
"build:ls": "yarn run compile:ls --define:process.env.NODE_ENV=\"'production'\" --minify-whitespace",
"esbuild": "esbuild --platform=node --tsconfig=./tsconfig.json --external:vscode --color=true --format=cjs",
"esbuild": "esbuild --platform=node --tsconfig=./tsconfig.json --external:vscode --color=true --format=cjs --loader:.node=file",
"prepackage": "yarn run build",
"package": "vsce package --yarn -o .",
"compile:ext": "yarn run esbuild --bundle ./src/extension.ts --outfile=./out/extension.js --target=es2017 --define:process.env.PRODUCT=\"'ext'\"",
Expand All @@ -67,7 +67,7 @@
"devDependencies": {
"@mysql/xdevapi": "^8.0.20",
"@sqltools/base-driver": "latest",
"@sqltools/types": "^0.1.7",
"@sqltools/types": "^0.2.0",
"@types/lodash": "^4.14.123",
"@types/mysql": "^2.15.12",
"compare-versions": "3.6.0",
Expand Down
58 changes: 43 additions & 15 deletions packages/driver.mysql/src/ls/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import generateId from '@sqltools/util/internal-id';

export default class MySQLDefault extends AbstractDriver<MySQLLib.Pool, MySQLLib.PoolOptions> implements IConnectionDriver {
queries = Queries;
public open() {
public async open() {
if (this.connection) {
return this.connection;
}
Expand All @@ -22,20 +22,48 @@ export default class MySQLDefault extends AbstractDriver<MySQLLib.Pool, MySQLLib
});
}

const pool = MySQLLib.createPool(this.credentials.connectString || {
connectTimeout: this.credentials.connectionTimeout * 1000,
database: this.credentials.database,
socketPath: this.credentials.socketPath,
host: this.credentials.server,
port: this.credentials.port,
password: this.credentials.password,
user: this.credentials.username,
multipleStatements: true,
dateStrings: true,
bigNumberStrings: true,
supportBigNumbers: true,
...mysqlOptions
});
let pool: MySQLLib.Pool;

if (this.credentials.connectString) {
pool = MySQLLib.createPool(this.credentials.connectString);
} else {
const poolConfig = {
host: this.credentials.server,
port: this.credentials.port,
connectTimeout: this.credentials.connectionTimeout * 1000,
database: this.credentials.database,
socketPath: this.credentials.socketPath,
password: this.credentials.password,
user: this.credentials.username,
multipleStatements: true,
dateStrings: true,
bigNumberStrings: true,
supportBigNumbers: true,
...mysqlOptions,
};

if (this.credentials.ssh === 'Enabled' && this.credentials.sshOptions) {
const { port: localPort } = await this.createSshTunnel(
{
host: this.credentials.sshOptions.host,
port: this.credentials.sshOptions.port,
username: this.credentials.sshOptions.username,
password: this.credentials.sshOptions.password,
privateKeyPath: this.credentials.sshOptions.privateKeyPath,
},
{
host: this.credentials.server,
port: this.credentials.port,
}
);
Object.assign(poolConfig, {
host: 'localhost',
port: localPort,
});
}

pool = MySQLLib.createPool(poolConfig);
}

return new Promise<MySQLLib.Pool>((resolve, reject) => {
pool.getConnection((err, conn) => {
Expand Down
Loading