Add support for MSSQL named instances

This commit is contained in:
Frederik Hummel 2020-10-03 11:23:34 +02:00
parent 4f3a03482e
commit 5f1a9d0280
3 changed files with 22 additions and 1 deletions

View File

@ -15,6 +15,7 @@ export default interface IConnectionOptions {
| "oracle"
| "sqlite";
schemaName: string;
instanceName: string;
ssl: boolean;
skipTables: string[];
onlyTables: string[];
@ -29,6 +30,7 @@ export function getDefaultConnectionOptions(): IConnectionOptions {
password: "",
databaseType: undefined as any,
schemaName: "",
instanceName: undefined as any,
ssl: false,
skipTables: [],
onlyTables: [],

View File

@ -188,6 +188,12 @@ function checkYargsParameters(options: options): options {
describe:
"Schema name to create model from. Only for mssql and postgres. You can pass multiple values separated by comma eg. -s scheme1,scheme2,scheme3",
},
i: {
alias: "instance",
string: true,
default: options.connectionOptions.instanceName,
describe: "Named instance to create model from. Only for mssql.",
},
ssl: {
boolean: true,
default: options.connectionOptions.ssl,
@ -425,6 +431,18 @@ async function useInquirer(options: options): Promise<options> {
])
).schema;
}
if (options.connectionOptions.databaseType === "mssql") {
options.connectionOptions.instanceName = (
await inquirer.prompt([
{
default: options.connectionOptions.instanceName,
message: "Named instance:",
name: "instanceName",
type: "input",
},
])
).instanceName;
}
options.connectionOptions.port = parseInt(answ.port, 10);
options.connectionOptions.host = answ.host;
options.connectionOptions.user = answ.login;

View File

@ -7,7 +7,8 @@
"username": "{{user}}",
"password": "{{password}}",
"database": "{{databaseName}}",{{#schemaName}}
"schema": "{{.}}",{{/schemaName}}
"schema": "{{.}}",{{/schemaName}}{{#instanceName}}
"extra": { "instanceName": "{{.}}" },{{/instanceName}}
"synchronize": false,
"entities": [
"entities/*.js"