Skip to content

Instantly share code, notes, and snippets.

@fravelgue
Created November 8, 2022 22:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fravelgue/cc0c4446a9bea697bc64b965eabe2ac8 to your computer and use it in GitHub Desktop.
Save fravelgue/cc0c4446a9bea697bc64b965eabe2ac8 to your computer and use it in GitHub Desktop.
Interactive (Polyglot) Notebook using SQLite
#!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