diff --git a/src/IConnectionOptions.ts b/src/IConnectionOptions.ts index f7dec18..ddc71e4 100644 --- a/src/IConnectionOptions.ts +++ b/src/IConnectionOptions.ts @@ -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: [], diff --git a/src/index.ts b/src/index.ts index 122cbcd..9fcd9ba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 { ]) ).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; diff --git a/src/templates/ormconfig.mst b/src/templates/ormconfig.mst index 800022e..aa7f80f 100644 --- a/src/templates/ormconfig.mst +++ b/src/templates/ormconfig.mst @@ -7,7 +7,8 @@ "username": "{{user}}", "password": "{{password}}", "database": "{{databaseName}}",{{#schemaName}} - "schema": "{{.}}",{{/schemaName}} + "schema": "{{.}}",{{/schemaName}}{{#instanceName}} + "extra": { "instanceName": "{{.}}" },{{/instanceName}} "synchronize": false, "entities": [ "entities/*.js"