How to use azdata - 10 common examples

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 / sqlops-firstresponderkit / src / placescript.ts View on Github external
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 / extension.ts View on Github external
let scriptText:string = "";
        const workbenchConfig = vscode.workspace.getConfiguration('newquerytemplate');
        let queryTemplateArray = new Array();
        queryTemplateArray = workbenchConfig.get('DefaultQueryTemplate');
        if (queryTemplateArray.length >= 1) {
            queryTemplateArray.forEach(function(scriptLine) {
                scriptText += scriptLine;
                scriptText += `
`;
            });
        }
        new placeScript().placescript(scriptText, context);
    };
    vscode.commands.registerCommand('dsk.newqueryoption', newQueryOption);
    azdata.tasks.registerTask('dsk.newqueryoption', ((context?: azdata.ObjectExplorerContext) => newQueryOption(context)));
    
    //dsk.resetDashboards
    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
github dzsquared / sqlops-firstresponderkit / src / updateCheck.ts View on Github external
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
            END
            
            select convert(varchar(10),@versionno,112) as versionno`;

            if (connectId) {
                let connectionUri = await sqlops.connection.getUriForConnection(connectId);
                let queryProvider = sqlops.dataprotocol.getProvider(context.connectionProfile.providerName, sqlops.DataProviderType.QueryProvider);
                let results = await queryProvider.runQueryAndReturn(connectionUri, query);
                let cell = results.rows[0][0];
                let currentVersion = cell.displayValue;

                //get live most recent version from github
                var options = {
                    uri: baseUrl,
                    headers: {
                        'Authorization': apitoken,
                        'User-Agent': 'Request-Promise'
                    },
                    json: true,
                    simple: false
                };
                var scriptText = await request.get(options);
                let recentVersion = scriptText.tag_name;

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 5 years ago

Package Health Score

63 / 100
Full package analysis

Similar packages