hook up add sql binding (#16838)

* hookup add sql binding

* fix typo

* addressing comments

* Addressing more comments

* add more comments
This commit is contained in:
Kim Santiago
2021-08-23 13:49:05 -07:00
committed by GitHub
parent 02dbac3b5f
commit b2be609c36
4 changed files with 147 additions and 26 deletions

View File

@@ -1,5 +1,7 @@
import * as vscode from 'vscode';
import { BindingType } from 'vscode-mssql';
import * as constants from '../common/constants';
import * as utils from '../common/utils';
export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined): Promise<void> {
if (!uri) {
@@ -8,8 +10,45 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined):
uri = vscode.window.activeTextEditor!.document.uri;
}
// 1. select input or output binding
const inputOutputItems: string[] = [constants.input, constants.output];
// get all the Azure functions in the file
const azureFunctionsService = await utils.getAzureFunctionService();
let getAzureFunctionsResult;
try {
getAzureFunctionsResult = await azureFunctionsService.getAzureFunctions(uri.fsPath);
} catch (e) {
vscode.window.showErrorMessage(e);
return;
}
const azureFunctions = getAzureFunctionsResult.azureFunctions;
if (azureFunctions.length === 0) {
vscode.window.showErrorMessage(constants.noAzureFunctionsInFile);
return;
}
// 1. select Azure function from the current file
const azureFunctionName = (await vscode.window.showQuickPick(azureFunctions, {
canPickMany: false,
title: constants.selectAzureFunction,
ignoreFocusOut: true
}));
if (!azureFunctionName) {
return;
}
// 2. select input or output binding
const inputOutputItems: (vscode.QuickPickItem & { type: BindingType })[] = [
{
label: constants.input,
type: BindingType.input
},
{
label: constants.output,
type: BindingType.output
}
];
const selectedBinding = (await vscode.window.showQuickPick(inputOutputItems, {
canPickMany: false,
@@ -21,29 +60,9 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined):
return;
}
// get all the azure functions in the file
// TODO: get actual functions. Need to add in sqltoolsservice first
const azureFunctions = ['af1', 'af2']; //await getAzureFunctions(uri);
if (azureFunctions.length === 0) {
vscode.window.showErrorMessage(constants.noAzureFunctionsInFile);
return;
}
// 2. select Azure function from the current file
const azureFunctionName = (await vscode.window.showQuickPick(azureFunctions, {
canPickMany: false,
title: constants.selectAzureFunction,
ignoreFocusOut: true
}));
if (!azureFunctionName) {
return;
}
// 3. ask for object name for the binding
const objectName = await vscode.window.showInputBox({
prompt: selectedBinding === constants.input ? constants.sqlObjectToQuery : constants.sqlTableToUpsert,
prompt: selectedBinding.type === BindingType.input ? constants.sqlObjectToQuery : constants.sqlTableToUpsert,
value: constants.placeHolderObject,
ignoreFocusOut: true
});
@@ -64,7 +83,17 @@ export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined):
return;
}
// TODO: hook up actually adding binding
// 5. insert binding
try {
const result = await azureFunctionsService.addSqlBinding(selectedBinding.type, uri.fsPath, azureFunctionName, objectName, connectionStringSetting);
if (!result.success) {
vscode.window.showErrorMessage(result.errorMessage);
return;
}
} catch (e) {
vscode.window.showErrorMessage(e);
return;
}
}