me.at.coding
me.at.coding

Reputation: 17744

Execute SQL from within an Azure Data Studio extension?

I want to create an extension for Azure Data Studio that accesses a database. The database (SQL Server) is already available in Azure Data Studio, as I am manually interacting with it.

Reading the Extensible API documentation it seems to be possible to access the databases available in Azure Data Studio. But how do I send SQL queries and receive their replies from within my extension code? What would be the SQL client for my extension code?

Upvotes: 3

Views: 697

Answers (1)

Max
Max

Reputation: 7100

I found no docs about this, however, I found myself this piece of code that works.

I don't know if this is a correct approach.

var connection = await azdata.connection.getCurrentConnection();

if (connection) {
    var uri = await azdata.connection.getUriForConnection(connection.connectionId);
    var g = azdata.dataprotocol.getProvidersByType(
        azdata.DataProviderType.QueryProvider
    )[0] as QueryProvider;
    var t = await g.runQueryAndReturn(
        uri,
        "SELECT TOP 1 * FROM sys.objects"
    );
    var jj = t.rows[0][0];

    vscode.window.showInformationMessage(jj.displayValue);
}

Upvotes: 3

Related Questions