NTDLS.SqliteDapperWrapper 1.3.3

dotnet add package NTDLS.SqliteDapperWrapper --version 1.3.3
                    
NuGet\Install-Package NTDLS.SqliteDapperWrapper -Version 1.3.3
                    
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.3.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NTDLS.SqliteDapperWrapper" Version="1.3.3" />
                    
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.3.3
                    
#r "nuget: NTDLS.SqliteDapperWrapper, 1.3.3"
                    
#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.3.3
                    
#: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.3.3
                    
Install as a Cake Addin
#tool nuget:?package=NTDLS.SqliteDapperWrapper&version=1.3.3
                    
Install as a Cake Tool

NTDLS.SqliteDapperWrapper

📦 Be sure to check out the NuGet package: 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, parsing complex multi-value parameters, attaching databases for inner-database joins, etc. All managed and wrapped in Dapper (hence the name).

Examples:

public static SqliteManagedInstance MyConnection { get; set; } = new("Data Source=.\\databaseFile.db");
public static SqliteManagedInstance 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 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 is compatible.  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 is compatible.  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 (1)

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

Package Downloads
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.3.3 700 12/3/2025
1.3.2 299 11/13/2025
1.3.1 196 8/15/2025
1.3.0 153 8/15/2025
1.2.1 208 5/2/2025
1.2.0 207 3/28/2025
1.1.6 181 3/1/2025
1.1.5 170 3/1/2025
1.1.4 305 12/31/2024
1.1.3 215 12/3/2024
1.1.2 250 9/11/2024
1.1.1 225 6/3/2024
1.1.0 194 6/3/2024
1.0.0 215 5/24/2024

Caching fixes and improvements to error messages.