Files
azuredatastudio/extensions/sql-bindings/src/extension.ts
Vasu Bhog 2d1ffeb47c Refactor vscode-mssql sql bindings logic to sql bindings ext (#18725)
* wip for refactor of mssql to sql-bindings

* remove STS dependency

* work to bring function over and setup with vscodeMsql APIs

* copy typings from vscode-mssql
2022-03-14 13:07:27 -07:00

39 lines
1.9 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { ITreeNodeInfo } from 'vscode-mssql';
import { getAzdataApi, getVscodeMssqlApi } from './common/utils';
import { launchAddSqlBindingQuickpick } from './dialogs/addSqlBindingQuickpick';
import { createAzureFunction } from './services/azureFunctionsService';
export async function activate(context: vscode.ExtensionContext): Promise<void> {
const vscodeMssqlApi = await getVscodeMssqlApi();
void vscode.commands.executeCommand('setContext', 'azdataAvailable', !!getAzdataApi());
// register the add sql binding command
context.subscriptions.push(vscode.commands.registerCommand('sqlBindings.addSqlBinding', async (uri: vscode.Uri | undefined) => { return launchAddSqlBindingQuickpick(uri); }));
// Generate Azure Function command
context.subscriptions.push(vscode.commands.registerCommand('sqlBindings.createAzureFunction', async (node: ITreeNodeInfo) => {
let connectionInfo = node.connectionInfo;
// set the database containing the selected table so it can be used
// for the initial catalog property of the connection string
let newNode: ITreeNodeInfo = node;
while (newNode) {
if (newNode.nodeType === 'Database') {
connectionInfo.database = newNode.metadata.name;
break;
} else {
newNode = newNode.parentNode;
}
}
const connectionDetails = vscodeMssqlApi.createConnectionDetails(connectionInfo);
const connectionString = await vscodeMssqlApi.getConnectionString(connectionDetails, false, false);
await createAzureFunction(connectionString, node.metadata.schema, node.metadata.name);
}));
}
export function deactivate(): void {
}