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?
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With