How to use the azdata.connection function in azdata

To help you get started, we’ve selected a few azdata examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dzsquared / query-editor-boost / src / extension.ts View on Github external
azdata.connection.getCurrentConnection().then( connection =>  {
            if (connection) {
                let databaseList = azdata.connection.listDatabases(connection.connectionId);
                changeDatabase(databaseList, connection);
            } else {
                vscode.window.showErrorMessage("No connection found.  Connect before switching databases.");
            }
        }, error => {
            console.info(error);
github dzsquared / sqlops-firstresponderkit / src / placescript.ts View on Github external
public async placescript(fileName, scriptText, context?: sqlops.ObjectExplorerContext) {
        var setting: vscode.Uri = vscode.Uri.parse("untitled:" + fileName);
        try {
            var connectId;
            if (context) {
                let connection = context.connectionProfile;
                connectId = connection.id;
            } else {
                let connection = await sqlops.connection.getCurrentConnection();
                connectId = connection.connectionId;
            }
            let doc = await vscode.workspace.openTextDocument(setting);
            let editor = await vscode.window.showTextDocument(doc, 1, false);
            editor.edit(edit => {
                edit.insert(new vscode.Position(0, 0), scriptText);
            });
            if (connectId) {
                await sqlops.queryeditor.connect(doc.uri.toString(), connectId);
            }
        } catch (err) {
            vscode.window.showErrorMessage(err);
        }
    }
}
github dzsquared / query-editor-boost / src / placescript.ts View on Github external
public async placescript(scriptText:string, context?:sqlops.ObjectExplorerContext) {
        try {
            var connection;
            if (context) {
                let connection = context.connectionProfile;
                this.connectionId = connection.id;
                this.dbName = connection.databaseName;
            } else {
                connection = await sqlops.connection.getCurrentConnection();
                if (connection) {
                    this.connectionId = connection.connectionId;
                    this.dbName = connection.databaseName;
                }
            }
            let doc = await vscode.workspace.openTextDocument({language: 'sql'});
            let editor = await vscode.window.showTextDocument(doc, 1, false);
            editor.edit(edit => {
                edit.insert(new vscode.Position(0, 0), scriptText);
            });
            
            const workbenchConfig = vscode.workspace.getConfiguration('newquerytemplate');
            let lineAt: number = workbenchConfig.get('DefaultQueryLine');
            let charAt: number = workbenchConfig.get('DefaultQueryCharacter');
            if (lineAt >= 0 && charAt >= 0) {
                let newPosition: vscode.Position = new vscode.Position(lineAt, charAt);
github dzsquared / query-editor-boost / src / extension.ts View on Github external
var useDatabaseCmd = () => {
        tH.sendTelemetry('useDatabaseCmd', { }, { });
        azdata.connection.getCurrentConnection().then( connection =>  {
            if (connection) {
                let databaseList = azdata.connection.listDatabases(connection.connectionId);
                changeDatabase(databaseList, connection);
            } else {
                vscode.window.showErrorMessage("No connection found.  Connect before switching databases.");
            }
        }, error => {
            console.info(error);
        });
    }
    var disposable_useDatabase = vscode.commands.registerCommand('dsk.useDatabase', useDatabaseCmd);
github dzsquared / query-editor-boost / src / changeDatabase.ts View on Github external
export async function changeDatabase(databaseList, connection) {
    let connectionUri = await azdata.connection.getUriForConnection(connection.connectionId);
    let dProvider = await azdata.dataprotocol.getProvider(connection.providerId, azdata.DataProviderType.ConnectionProvider);
    
    if (dProvider.providerId == "MSSQL") {
        let selectedDatabase = await vscode.window.showQuickPick(databaseList, 
            { placeHolder: 'Select Database', "ignoreFocusOut": true}
        );
        let useThisDB = selectedDatabase;
        
        await dProvider.changeDatabase(connectionUri,useThisDB);
        await azdata.queryeditor.connect(vscode.window.activeTextEditor.document.uri.toString(), connection.connectionId);
    } else {
        vscode.window.showErrorMessage("Sorry, use database is only supported for MS SQL");
    }
};
github dzsquared / query-editor-boost / src / connectHolder.ts View on Github external
export async function hangOnToConnection(): Promise {
        let connectProf = await azdata.connection.getCurrentConnection();
        let connectHoldId : string = '';
        let dbName: string = '';
        let providerId: string = '';
        connectHoldId = connectProf.connectionId;
        dbName = connectProf.databaseName;
        providerId = connectProf.providerId;
        
        return {connectHoldId: connectHoldId, dbName: dbName, providerId: providerId};
    }
github dzsquared / sqlops-firstresponderkit / src / updateCheck.ts View on Github external
public async checkForUpdates(context?: sqlops.ObjectExplorerContext): Promise {
        let baseUrl = "https://api.github.com/repos/BrentOzarULTD/SQL-Server-First-Responder-Kit/releases/latest";

        let apitoken = 'token ' + apiconfig.token;
        vscode.window.showInformationMessage("Checking First Responder Kit for Updates");
        
        try {
            var connectId;
            if (context) {
                let connection = context.connectionProfile;
                connectId = connection.id;
            } else {
                let connection = await sqlops.connection.getCurrentConnection();
                connectId = connection.connectionId;
            }

            let query = `declare @versionno datetime
            DECLARE @VERSION VARCHAR(30)
            
            IF OBJECT_ID('dbo.sp_Blitz') IS NULL
            set @versionno = '1/1/1900'
            ELSE
            BEGIN
                BEGIN TRY
                    exec sp_blitz @VERSIONCHECKMODE = 1, @VERSION = @VERSION OUTPUT, @versiondate = @versionno output;
                END TRY
                BEGIN CATCH
                    exec sp_blitz @help = 1, @versiondate = @versionno output
                END CATCH

azdata

The azdata NPM module provides Azure Data Studio extension authors tools to write extensions. It provides the azdata.d.ts node module (all accessible API for extensions) as well as commands for compiling and testing extensions.

MIT
Latest version published 6 years ago

Package Health Score

63 / 100
Full package analysis