-
-
Save martinandersen3d/40eac9bc11a2a129ee31802e636868d3 to your computer and use it in GitHub Desktop.
Interactive (Polyglot) Notebook using SQLite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!markdown | |
# Using SQLite in Notebook | |
Install ExtensionLab NuGet package | |
#!csharp | |
#r "nuget: System.Data.SQLite, *-*" | |
#r "nuget: Microsoft.DotNet.Interactive.ExtensionLab, *-*" | |
#r "nuget: Dapper, *-*" | |
#!csharp | |
#!lsmagic | |
#!markdown | |
Installing the `ExtensionLab` brings in some new magic commands including two additional verbs for the `#!connect` command, which you can see by running help for it. | |
#!csharp | |
#!connect -h | |
#!csharp | |
#!connect sqlite -h | |
#!markdown | |
## Using SQLite in SQL Notebook | |
This sample demonstrates how to use the `#!connect` extension | |
#!csharp | |
#!connect sqlite --kernel-name hellodb "Data Source=helloDB;Mode=Memory;Cache=Shared" | |
#!sql | |
#!sql-hellodb | |
select 10; | |
#!markdown | |
## Using Dapper and SQLite in C# Notebook | |
#!csharp | |
using System.Data.SQLite; | |
using Dapper; | |
using (var conn = new SQLiteConnection("Data Source=helloDB;Mode=Memory;Cache=Shared")) | |
{ | |
var res = conn.Query<int>("SELECT 50").FirstOrDefault(); | |
Console.WriteLine($"Result: {res}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment