Insert sql binding into Azure function quick pick (#16553)

* initial quick pick

* move constants

* remove commented code for now

* addressing comments

* update name

* update name in other places

* remove azure functions from name and rename file
This commit is contained in:
Kim Santiago
2021-08-05 12:11:30 -07:00
committed by GitHub
parent 35983659b1
commit 33baaa475d
5 changed files with 97 additions and 1 deletions

View File

@@ -384,3 +384,16 @@ export const defaultDSP = targetPlatformToVersion.get(defaultTargetPlatform)!;
export function getTargetPlatformFromVersion(version: string): string {
return Array.from(targetPlatformToVersion.keys()).filter(k => targetPlatformToVersion.get(k) === version)[0];
}
// Insert SQL binding
export const hostFileName = 'host.json';
export const placeHolderObject = '[dbo].[table1]';
export const input = localize('input', "Input");
export const output = localize('output', "Output");
export const selectBindingType = localize('selectBindingType', "Select type of binding");
export const selectAzureFunction = localize('selectAzureFunction', "Select an Azure function in the current file to add SQL binding to");
export const sqlObjectToQuery = localize('sqlObjectToQuery', "SQL object to query");
export const sqlTableToUpsert = localize('sqlTableToUpsert', "SQL table to upsert into");
export const connectionStringSetting = localize('connectionStringSetting', "Connection string setting name");
export const connectionStringSettingPlaceholder = localize('connectionStringSettingPlaceholder', "Connection string setting specified in \"local.settings.json\"");
export const noAzureFunctionsInFile = localize('noAzureFunctionsInFile', "No Azure functions in the current active file");

View File

@@ -13,6 +13,7 @@ import { NetCoreTool } from '../tools/netcoreTool';
import { IconPathHelper } from '../common/iconHelper';
import { WorkspaceTreeItem } from 'dataworkspace';
import { SqlDatabaseProjectProvider } from '../projectProvider/projectProvider';
import { launchAddSqlBindingQuickpick } from '../dialogs/addSqlBindingQuickpick';
/**
* The main controller class that initializes the extension
@@ -69,6 +70,8 @@ export default class MainController implements vscode.Disposable {
vscode.commands.registerCommand('sqlDatabaseProjects.changeTargetPlatform', async (node: WorkspaceTreeItem) => { await this.projectsController.changeTargetPlatform(node); });
vscode.commands.registerCommand('sqlDatabaseProjects.validateExternalStreamingJob', async (node: WorkspaceTreeItem) => { await this.projectsController.validateExternalStreamingJob(node); });
vscode.commands.registerCommand('sqlDatabaseProjects.addSqlBinding', async (uri: vscode.Uri | undefined) => { await launchAddSqlBindingQuickpick(uri); });
IconPathHelper.setExtensionContext(this.extensionContext);
await templates.loadTemplates(path.join(this.context.extensionPath, 'resources', 'templates'));

View File

@@ -0,0 +1,70 @@
import * as vscode from 'vscode';
import * as constants from '../common/constants';
export async function launchAddSqlBindingQuickpick(uri: vscode.Uri | undefined): Promise<void> {
if (!uri) {
// this command only shows in the command palette when the active editor is a .cs file, so we can safely assume that's the scenario
// when this is called without a uri
uri = vscode.window.activeTextEditor!.document.uri;
}
// 1. select input or output binding
const inputOutputItems: string[] = [constants.input, constants.output];
const selectedBinding = (await vscode.window.showQuickPick(inputOutputItems, {
canPickMany: false,
title: constants.selectBindingType,
ignoreFocusOut: true
}));
if (!selectedBinding) {
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,
value: constants.placeHolderObject,
ignoreFocusOut: true
});
if (!objectName) {
return;
}
// 4. ask for connection string setting name
// TODO: load local settings from local.settings.json like in LocalAppSettingListStep in vscode-azurefunctions repo
const connectionStringSetting = await vscode.window.showInputBox({
prompt: constants.connectionStringSetting,
placeHolder: constants.connectionStringSettingPlaceholder,
ignoreFocusOut: true
});
if (!connectionStringSetting) {
return;
}
// TODO: hook up actually adding binding
// 5. insert binding
}