NTDLS.SqliteDapperWrapper 1.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package NTDLS.SqliteDapperWrapper --version 1.1.2
                    
NuGet\Install-Package NTDLS.SqliteDapperWrapper -Version 1.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NTDLS.SqliteDapperWrapper" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NTDLS.SqliteDapperWrapper" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="NTDLS.SqliteDapperWrapper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NTDLS.SqliteDapperWrapper --version 1.1.2
                    
#r "nuget: NTDLS.SqliteDapperWrapper, 1.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NTDLS.SqliteDapperWrapper@1.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NTDLS.SqliteDapperWrapper&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=NTDLS.SqliteDapperWrapper&version=1.1.2
                    
Install as a Cake Tool

NTDLS.SqliteDapperWrapper

📦 Be sure to check out the NuGet pacakge: https://www.nuget.org/packages/NTDLS.SqliteDapperWrapper

Provides a simple interface to a Sqlite database and allows for more advanced options such as executing embedded scripts, passing parameters, parring complext multi-value parameters, attaching databases for inner-database joins, etc. All managed and wrapped in Dapper (hence the name).

Examples:

public static ManagedDataStorageFactory MyConnection { get; set; } = new("Data Source=.\\databaseFile.db");
public static ManagedDataStorageFactory MyOtherDatabase { get; set; } = new("Data Source=.\\otherDatabase.db");
//Each time a statement/query is executed, the NTDLS.SqliteDapperWrapper will
//  open a connection, execute then close & dispose the connection. 

MyConnection.Execute("DROP TABLE IF EXISTS Test");
MyOtherDatabase.Execute("DROP TABLE IF EXISTS Test");

//Creates a table in two different databases from a script that is an embedded resource in the project.
MyConnection.Execute("CreateTestTable.sql");
MyOtherDatabase.Execute("CreateTestTable.sql");

//Deletes the data from the table "Test".
MyConnection.Execute("DELETE FROM Test");
MyOtherDatabase.Execute("DELETE FROM Test");
//Insert some records using an inline statement and parameters.
for (int i = 0; i < 100; i++)
{
    var param = new
    {
        Name = $"Name #{i}",
        Description = Guid.NewGuid().ToString()
    };

    MyConnection.Execute("INSERT INTO Test (Name, Description) VALUES (@Name, @Description)", param);
}
//We can use "Ephemeral" to perform multiple steps on the same connection, such as here where we
//  begin a transaction, insert data and then optionally commit or rollback the transaction.
//  The connection is closed and disposed after Ephemeral() executes.
MyConnection.Ephemeral(o =>
{
    using var tx = o.BeginTransaction();

    try
    {
        for (int i = 0; i < 100; i++)
        {
            var param = new
            {
                Name = $"Name #{i}",
                Description = Guid.NewGuid().ToString()
            };

            o.Execute("INSERT INTO Test (Name, Description) VALUES (@Name, @Description)", param);
        }

        tx.Commit();
    }
    catch
    {
        tx.Rollback();
        throw;
    }
});
MyConnection.Ephemeral(o =>
{
    List<int> ids = [10, 20, 30, 40, 50, 60, 70, 80];

    //By calling CreateTempTableFrom, we can create a temp table with the given name that
    //  contains the given values. This allows us to pass ranges of values to a script.
    //  The temp table is automatically dropped them the variable is disposed.
    using var id_temp = o.CreateTempTableFrom("id_temp", ids);

    //Here we are going to get the values with the id of 10, 20, 30, etc.
    var results = o.Query<TestModel>("SELECT * FROM Test INNER JOIN id_temp ON id_temp.Value = Test.Id");

    //Print the results.
    foreach (var result in results)
    {
        Console.WriteLine($"{result.Id} {result.Name} {result.Description}");
    }
});
//Make some dummy records so we can pass them as a temp table.
var values = new List<TestParamModel>();
for (int i = 0; i < 100; i++)
{
    values.Add(new TestParamModel
    {
        Name = $"Name #{i}",
        Description = Guid.NewGuid().ToString()
    });
}
//Insert some data into the "Other Database".
MyOtherDatabase.Ephemeral(o =>
{
    //By calling CreateTempTableFrom, we can create a temp table with the given name that
    //  contains the given values from a list of anonymous or well defined objects.
    //  This allows us to pass ranges of values to a script. The temp table is automatically
    //  dropped them the variable is disposed.
    using var temp_values = o.CreateTempTableFrom("temp_values", values);

    //Here we are going to insert the data from the temp table called "temp_values".
    o.Execute("INSERT INTO Test (Name, Description) SELECT Name, Description FROM temp_values");
});
MyConnection.Ephemeral(o =>
{
    //We can "attach" another database and access data from it like they are both attached.
    //The database is automatically "unattached" when the variable is disposed.
    using var otherDatabase = o.Attach("otherDatabase.db", "MyOtherDatabase");

    //Here we are going join to another database and select some values.
    var results = o.Query<JoinedModel>
            ("SELECT A.Id, a.Name as NameA, b.Name as NameB FROM Test as A INNER JOIN MyOtherDatabase.Test as B ON A.Id = B.Id");

    //Print the results.
    foreach (var result in results)
    {
        Console.WriteLine($"{result.Id} {result.NameA} {result.NameB}");
    }
});

License

MIT

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on NTDLS.SqliteDapperWrapper:

Package Downloads
TightWiki.Plugin

TightWiki is a modern, open-source wiki platform with zero configuration and full control. Built on ASP.NET Core with SQLite, it runs anywhere, works instantly, and looks great doing it.

Ae.Engine

Axis Engine is a 2D game engine written in C# and rendered with DirectX.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.2 241 3/25/2026
1.4.1 92 3/25/2026
1.4.0 93 3/22/2026
1.3.3 729 12/3/2025
1.3.2 306 11/13/2025
1.3.1 199 8/15/2025
1.3.0 159 8/15/2025
1.2.1 212 5/2/2025
1.2.0 213 3/28/2025
1.1.6 184 3/1/2025
1.1.5 173 3/1/2025
1.1.4 312 12/31/2024
1.1.3 223 12/3/2024
1.1.2 254 9/11/2024
1.1.1 228 6/3/2024
1.1.0 198 6/3/2024
1.0.0 224 5/24/2024

Added ability to specify "folder name" embedded resources.