-
Notifications
You must be signed in to change notification settings - Fork 368
/
MsSqlKernelExtension.cs
35 lines (29 loc) · 1.45 KB
/
MsSqlKernelExtension.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.DotNet.Interactive.Utility;
namespace Microsoft.DotNet.Interactive.SqlServer;
public class MsSqlKernelExtension : IKernelExtension
{
public async Task OnLoadAsync(Kernel kernel)
{
if (kernel is CompositeKernel compositeKernel)
{
var sqlToolName = "MicrosoftSqlToolsServiceLayer";
await Utils.CheckAndInstallGlobalToolAsync(sqlToolName, "1.2.0", "Microsoft.SqlServer.SqlToolsServiceLayer.Tool");
var sqlToolPath = Path.Combine(Paths.DotnetToolsPath, sqlToolName);
compositeKernel
.AddKernelConnector(new ConnectMsSqlCommand(sqlToolPath));
compositeKernel
.SubmissionParser
.SetInputTypeHint(typeof(MsSqlConnectionString), "connectionstring-mssql");
KernelInvocationContext.Current?.Display(
new HtmlString(@"<details><summary>Query Microsoft SQL Server databases.</summary>
<p>This extension adds support for connecting to Microsoft SQL Server databases using the <code>#!connect mssql</code> magic command. For more information, run a cell using the <code>#!sql</code> magic command.</p>
</details>"),
"text/html");
}
}
}