mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-04 01:25:38 -05:00
Add Table Menu for SQL Bindings promptForObjectName (#19358)
* first wip for table menu prompt * fix up some table prompts * use simpleExecuteRequest * fix table prompt scenario for sql binding also * fix/add more testing and address comments * add brackets to selected database * add manually entered option
This commit is contained in:
@@ -11,7 +11,7 @@ import * as azureFunctionsUtils from '../common/azureFunctionsUtils';
|
||||
import * as constants from '../common/constants';
|
||||
import * as azureFunctionsContracts from '../contracts/azureFunctions/azureFunctionsContracts';
|
||||
import { CreateAzureFunctionStep, TelemetryActions, TelemetryReporter, TelemetryViews, ExitReason } from '../common/telemetry';
|
||||
import { AddSqlBindingParams, BindingType, GetAzureFunctionsParams, GetAzureFunctionsResult, ResultStatus } from 'sql-bindings';
|
||||
import { AddSqlBindingParams, BindingType, GetAzureFunctionsParams, GetAzureFunctionsResult, IConnectionStringInfo, ResultStatus } from 'sql-bindings';
|
||||
import { IConnectionInfo, ITreeNodeInfo } from 'vscode-mssql';
|
||||
import { createAddConnectionStringStep } from '../createNewProject/addConnectionStringStep';
|
||||
|
||||
@@ -83,6 +83,7 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
||||
return;
|
||||
}
|
||||
projectFolder = projectFolders[0].fsPath;
|
||||
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, telemetryStep)
|
||||
.withAdditionalProperties(propertyBag).send();
|
||||
break;
|
||||
@@ -125,45 +126,13 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
||||
}
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, telemetryStep)
|
||||
.withAdditionalProperties(propertyBag).withConnectionInfo(connectionInfo).send();
|
||||
telemetryStep = CreateAzureFunctionStep.getConnectionProfile;
|
||||
let connectionURI: string = '';
|
||||
try {
|
||||
await vscode.window.withProgress(
|
||||
{
|
||||
location: vscode.ProgressLocation.Notification,
|
||||
title: constants.connectionProgressTitle,
|
||||
cancellable: false
|
||||
}, async (_progress, _token) => {
|
||||
// list databases based on connection profile selected
|
||||
connectionURI = await vscodeMssqlApi.connect(connectionInfo!);
|
||||
}
|
||||
);
|
||||
} catch (e) {
|
||||
// mssql connection error will be shown to the user
|
||||
// we will then prompt user to choose a connection profile again
|
||||
continue;
|
||||
}
|
||||
// list databases based on connection profile selected
|
||||
telemetryStep = CreateAzureFunctionStep.getDatabase;
|
||||
let listDatabases = await vscodeMssqlApi.listDatabases(connectionURI);
|
||||
const selectedDatabase = (await vscode.window.showQuickPick(listDatabases, {
|
||||
canPickMany: false,
|
||||
title: constants.selectDatabase,
|
||||
ignoreFocusOut: true
|
||||
}));
|
||||
|
||||
if (!selectedDatabase) {
|
||||
// User cancelled
|
||||
// we will then prompt user to choose a connection profile again
|
||||
continue;
|
||||
}
|
||||
connectionInfo.database = selectedDatabase;
|
||||
telemetryStep = CreateAzureFunctionStep.getObjectName;
|
||||
|
||||
// prompt user for object name to create function from
|
||||
objectName = await azureFunctionsUtils.promptForObjectName(selectedBinding);
|
||||
objectName = await azureFunctionsUtils.promptForObjectName(selectedBinding, connectionInfo);
|
||||
if (!objectName) {
|
||||
// user cancelled
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -213,16 +182,20 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
||||
let templateId: string = selectedBindingType === BindingType.input ? constants.inputTemplateID : constants.outputTemplateID;
|
||||
|
||||
// prompt for Connection String Setting Name
|
||||
let connectionStringSettingName: string | undefined = constants.sqlConnectionStringSetting;
|
||||
let connectionStringInfo: IConnectionStringInfo | undefined = { connectionStringSettingName: constants.sqlConnectionStringSetting, connectionInfo: connectionInfo };
|
||||
if (!isCreateNewProject && projectFile) {
|
||||
telemetryStep = CreateAzureFunctionStep.getConnectionStringSettingName;
|
||||
connectionStringSettingName = await azureFunctionsUtils.promptAndUpdateConnectionStringSetting(vscode.Uri.parse(projectFile), connectionInfo);
|
||||
connectionStringInfo = await azureFunctionsUtils.promptAndUpdateConnectionStringSetting(vscode.Uri.parse(projectFile), connectionInfo);
|
||||
if (!connectionStringInfo) {
|
||||
// User cancelled connection string setting name prompt or connection string method prompt
|
||||
return;
|
||||
}
|
||||
TelemetryReporter.createActionEvent(TelemetryViews.CreateAzureFunctionWithSqlBinding, telemetryStep)
|
||||
.withAdditionalProperties(propertyBag)
|
||||
.withConnectionInfo(connectionInfo).send();
|
||||
}
|
||||
// addtional execution step that will be used by vscode-azurefunctions to execute only when creating a new azure function project
|
||||
let connectionStringExecuteStep = createAddConnectionStringStep(projectFolder, connectionInfo, connectionStringSettingName);
|
||||
let connectionStringExecuteStep = createAddConnectionStringStep(projectFolder, connectionInfo, connectionStringInfo.connectionStringSettingName);
|
||||
|
||||
// create C# Azure Function with SQL Binding
|
||||
telemetryStep = 'createFunctionAPI';
|
||||
@@ -233,7 +206,7 @@ export async function createAzureFunction(node?: ITreeNodeInfo): Promise<void> {
|
||||
templateId: templateId,
|
||||
functionName: functionName,
|
||||
functionSettings: {
|
||||
connectionStringSetting: connectionStringSettingName,
|
||||
connectionStringSetting: connectionStringInfo.connectionStringSettingName,
|
||||
...(selectedBindingType === BindingType.input && { object: objectName }),
|
||||
...(selectedBindingType === BindingType.output && { table: objectName })
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user