Thomas.Database 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Thomas.Database --version 2.0.0
                    
NuGet\Install-Package Thomas.Database -Version 2.0.0
                    
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="Thomas.Database" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Thomas.Database" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Thomas.Database" />
                    
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 Thomas.Database --version 2.0.0
                    
#r "nuget: Thomas.Database, 2.0.0"
                    
#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 Thomas.Database@2.0.0
                    
#: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=Thomas.Database&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Thomas.Database&version=2.0.0
                    
Install as a Cake Tool

alternate text is missing from this package README image ThomasDataAdapter

It Works matching class fields vs result set returned by database query. There are simple configurations for applications that need fast response time without must deal with database connections.

Features released 2.0.0:

  • Set a unique signature for each database settings that must instantiate statically a database context whenever you want.
  • Straightforward way to match typed and anonymous types to query parameters.
  • Attributes to match parameter direction and size to configure DbParameter.
  • Optional Cache layer to boost application performance having control what will be stored, updated and removed.

Nuget : https://www.nuget.org/packages/ThomasDataAdapter.SqlServer/

Basic configuration in startup.cs :

using Thomas.Database.SqlServer;
.
.
.
SqlServerFactory.AddDb(new DbSettings 
{
    Signature = "mssqldb1",
    StringConnection = @"Data Source={SourceName};Initial Catalog={database};User ID={User};Password={Pass}"
});

Custom configuration :

using Thomas.Database.SqlServer;
.
.
.
SqlServerFactory.AddDb(new DbSettings { 
    Signature = "mssqldb1",
    StringConnection = @"Data Source={SourceName};Initial Catalog={database};User ID={User};Password={Pass}",
    DetailErrorMessage = true,
    ConnectionTimeout = 300,
    SensitiveDataLog = true
 });

Inject IThomasDb interface in your component:

public class MyComponent
{
    private readonly IThomasDb _db;

    public IList<Person> GetPeople()
    {
        var _db = DbFactory.CreateDbContext("mssqldb1");
        var response = _db.ToListOp<Person>("dbo.GetPeople");

        if(response.Success)
        {
            return response.Result;
        }
        else
        {
            Log.WriteLog(response.ErrorMessage);
        }
    }

    public void SavePeople(Person person)
    {
        var _db = DbFactory.CreateDbContext("mssqldb1");
        var response = _db.ExecuteOp(person, "dbo.SavePerson");

        if(response.Success)
        {
            .
            .
            .
        }
        else
        {
            Log.WriteLog(response.ErrorMessage);
        }
    }

    public void UpdateAge(string name, int age)
    {
        var _db = DbFactory.CreateDbContext("mssqldb1");
        var response = _db.ExecuteOp(new { vcName = name, nbAge = age}, "dbo.UpdateAge");

        if(response.Success)
        {
            .
            .
            .
        }
        else
        {
            Log.WriteLog(response.ErrorMessage);
        }
    }

    public void ProcessData()
    {
        var _db = DbFactory.CreateDbContext("mssqldb1");
        var response = _db.ToTupleOp<Person, Office>("dbo.GetDataForProcess");

        if(response.Success)
        {
            IReadOnlyList<Person> persons = response.Result.Item1;
            IReadOnlyList<Office> offices = response.Result.Item2;
            .
            .
            .
        }
        else
        {
            Log.WriteLog(response.ErrorMessage);
        }
    }

    public void ManyFormsToGetData()
    {
        var _db = DbFactory.CreateDbContext("mssqldb1");

        Person person = _db.ToSingle<Person>("SELECT * FROM Person WHERE Id = 43");

        IReadOnlyList<Person> people = _db.ToList<Person>("SELECT * FROM Person WHERE name like '%jhon%'");

        Tuple<IReadOnlyList<Person>, IReadOnlyList<Office>> peopleOffice = _db.Tuple<Person, Office>("SELECT * FROM Person WHERE name like '%jhon%'; SELECT * FROM Office WHERE name like '%US_%");
    }
}

Options to configure:

Perfomance

The benchmark is in project Thomas.Tests.Performance

dotnet run -p .\Thomas.Tests.Performance\ -c Release -f net5.0 -- -f * --join

BenchmarkDotNet=v0.13.0, OS=Windows 10.0.19042.1466 (20H2/October2020Update)
Intel Core i7-8550U CPU 1.80GHz (Kaby Lake R), 1 CPU, 8 logical and 4 physical cores
.NET SDK=5.0.404
  [Host]     : .NET Core 3.1.22 (CoreCLR 4.700.21.56803, CoreFX 4.700.21.57101), X64 RyuJIT
  ShortRun   : .NET Core 3.1.22 (CoreCLR 4.700.21.56803, CoreFX 4.700.21.57101), X64 RyuJIT
  Job-QAXZEQ : .NET Core 3.1.22 (CoreCLR 4.700.21.56803, CoreFX 4.700.21.57101), X64 RyuJIT

Namespace=Thomas.Tests.Performance.Benchmark  Type=ThomasDataAdapterBenckmark


Detailed Runtime Type Method Mean StdDev Error Op/s GcMode Completed Work Items Lock Contentions Gen0 Allocated
.NET 8.0.1 (8.0.123.58001) ThomasDataAdapterBenckmark 'ToList<> (buffered)' 881.0 ns 24.99 ns 17.42 ns 1,135,053.3 Toolchain=.NET 8.0 - - 0.0343 440 B
.NET Core 3.1.32 (CoreCLR 4.700.22.55902 ThomasDataAdapterBenckmark 'ToList<> (buffered)' 1,066.4 ns 0.00 ns NA 937,747.7 ShortRun 0.0000 - 0.0488 624 B
.NET 8.0.1 (8.0.123.58001) DapperBenckmark 'Query<T> List (unbuffered)' 558,085.4 ns 24,088.59 ns 10,974.18 ns 1,791.8 Toolchain=.NET 8.0 - - - 8481 B
.NET Core 3.1.32 (CoreCLR 4.700.22.55902 DapperBenckmark 'Query<T> List (unbuffered)' 561,390.1 ns 0.00 ns NA 1,781.3 ShortRun 0.0013 - 0.6250 8168 B
.NET Core 3.1.32 (CoreCLR 4.700.22.55902 ThomasDataAdapterBenckmark 'ToList<> (unbuffered)' 562,313.2 ns 0.00 ns NA 1,778.4 ShortRun 0.0013 - 0.6250 10760 B
.NET Core 3.1.32 (CoreCLR 4.700.22.55902 DapperBenckmark 'Query<dynamic> (buffered)' 567,313.9 ns 0.00 ns NA 1,762.7 ShortRun 0.0013 - 0.6250 8384 B
.NET Core 3.1.32 (CoreCLR 4.700.22.55902 DapperBenckmark 'Query<T> (unbuffered)' 570,249.6 ns 0.00 ns NA 1,753.6 ShortRun 0.0013 - 0.6250 8096 B
.NET 8.0.1 (8.0.123.58001) ThomasDataAdapterBenckmark 'ToList<> (unbuffered)' 592,551.6 ns 22,874.55 ns 11,727.99 ns 1,687.6 Toolchain=.NET 8.0 - - - 10161 B
.NET 8.0.1 (8.0.123.58001) DapperBenckmark 'Query<dynamic> (buffered)' 593,874.5 ns 29,064.91 ns 11,758.83 ns 1,683.9 Toolchain=.NET 8.0 - - - 8577 B
.NET 8.0.1 (8.0.123.58001) DapperBenckmark 'Query<T> (unbuffered)' 632,908.2 ns 32,045.51 ns 12,589.98 ns 1,580.0 Toolchain=.NET 8.0 - - - 8025 B
.NET Core 3.1.32 (CoreCLR 4.700.22.55902 DapperBenckmark 'Query<T> (unbuffered)' 1,000,659.2 ns 0.00 ns NA 999.3 ShortRun 0.0025 - - 8464 B
.NET 8.0.1 (8.0.123.58001) DapperBenckmark 'Query<T> (unbuffered)' 1,032,863.4 ns 30,836.70 ns 20,192.91 ns 968.2 Toolchain=.NET 8.0 - - - 8249 B
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
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 Thomas.Database:

Package Downloads
ThomasDataAdapter.SqlServer

Simple library to get data from Database SQL Server specially high load and low memory consum.

Thomas.Cache

ThomasDataAdapter Cache Layer to boost performance with dynamic cache refresh capabilities.

GitHub repositories

This package is not used by any popular GitHub repositories.

Features released 2.0.0:

- Set a unique signature for each database settings that must instantiate statically a database context whenever you want.
- Straightforward way to match typed and anonymous types to query parameters.
- Attributes to match parameter direction and size to configure DbParameter.
- Optional Cache layer to boost application performance having control what will be stored, updated and removed.