Lib.Db 2.1.0

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

Lib.Db v2.1.0

Extreme Performance Data Access Library for .NET 10+

.NET NuGet AOT Ready License


v2.1.0 소개

Lib.Db v2.1.0는 .NET 10 애플리케이션을 위한 고성능 SQL Server 데이터 액세스 라이브러리입니다.

  • Fluent API Only: IDbSession 단일 진입점에서 3-Stage Fluent API로 모든 쿼리를 실행합니다
  • DbResult<T>: 예외 대신 결과 타입으로 성공/실패를 구분합니다 (패턴 매칭 지원)
  • 멀티 DB: ConnectionStringNames 리스트로 N개 DB를 동시 지원합니다
  • Zero-Allocation: Span<T>, ArrayPool, SqlInterpolatedStringHandler로 힙 할당을 최소화합니다
  • AOT-First: Source Generator 기반으로 리플렉션 없이 Native AOT를 완벽 지원합니다
  • Resilience: Polly v8 파이프라인 내장으로 자동 재시도 및 Circuit Breaker를 제공합니다

빠른 시작

1. appsettings.json

{
  "ConnectionStrings": {
    "Default": "Server=localhost;Database=MyDb;User Id=app_user;Password=***;TrustServerCertificate=True;"
  },
  "LibDb": {
    "ConnectionStringNames": ["Default"],
    "EnableSchemaCaching": true,
    "EnableResilience": true
  }
}

2. DI 등록

using Microsoft.Extensions.Hosting;

HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Services.AddLibDb(builder.Configuration);

IHost host = builder.Build();
await host.RunAsync();

3. 사용

using Lib.Db.Contracts.Core;
using Lib.Db.Contracts.Entry;

public sealed class UserRepository(IDbSession session)
{
    public record User(int Id, string Name, string Email);

    public async Task<User?> GetUserAsync(int id)
    {
        DbResult<User?> result = await session.Default
            .Procedure("dbo.usp_GetUser")
            .With(new { Id = id })
            .QuerySingleAsync<User>();

        return result.IsSuccess ? result.Value : null;
    }

    public async Task<int> RegisterAsync(string name, string email)
    {
        DbResult<int> result = await session.Default
            .Sql($"INSERT INTO Users (Name, Email) VALUES ({name}, {email}); SELECT SCOPE_IDENTITY();")
            .ExecuteScalarAsync<int>();

        return result.IsSuccess ? result.Value ?? 0 : -1;
    }
}

주요 기능

기능 설명
3-Stage Fluent API IProcedureStageIParameterStageIExecutionStage 타입 안전 체이닝
DbResult<T> 예외 없이 성공/실패를 구분하는 불변 결과 타입 (Deconstruct, 패턴 매칭)
멀티 DB session.Use("DB1") / session.Use("DB2") 병렬 실행
트랜잭션 BeginTransactionAsync → CommitAsync/RollbackAsync (자동 롤백)
Zero-Allocation SQL SqlInterpolatedStringHandler로 힙 할당 0, SQL Injection 자동 방지
Source Generator [TvpRow], [DbResult] 어노테이션으로 컴파일 타임 코드 생성
Native AOT 리플렉션 제로, Shadow DTO 패턴으로 AOT 완벽 호환
Polly v8 Resilience 자동 재시도, Circuit Breaker, Deadlock 처리 내장
L1+L2 캐시 MemoryCache + SharedMemoryCache(MMF) 하이브리드 스키마 캐싱
스키마 워밍업 앱 시작 시 SP 메타데이터 사전 로딩 (Include/Exclude 패턴)
OpenTelemetry ActivitySource/Meter 통합 메트릭 수집

성능

시나리오 Dapper EF Core Lib.Db v2.1.0 개선율
단순 조회 (1,000건) 12.3ms 18.7ms 8.1ms +34%
메모리 사용량 1.23MB 2.45MB 0.78MB -37%
GC Gen0 수집 150회 320회 28회 -81%

위 수치는 예시이며, 실제 환경에 따라 다를 수 있습니다.


v2.1.0 변경 요약

항목 v1 v2.1.0
진입점 IDbContext IDbSession
실행 경로 13개 5개 (통합)
에러 처리 throw 예외 DbResult<T> 결과 타입
DB 연결 ConnectionStringName (단수) ConnectionStringNames (복수 리스트)
트랜잭션 결과 void / 예외 DbResult<bool>
API 스타일 다중 인터페이스 Fluent API Only

호환성

Platform .NET SQL Server Status
Windows .NET 10 SQL Server 2016+ 지원
Linux .NET 10 SQL Server 2017+ 지원
macOS .NET 10 SQL Server 2017+ 지원
Native AOT .NET 10 모든 버전 지원

기술 문서

핵심 가이드

Source Generator

  • Lib.Db.TvpGen -- TVP 자동 생성, DbDataReader 매핑, Track 5 알고리즘

NuGet 패키지

  • Lib.Db -- 런타임 라이브러리 (Source Generator 내장)
  • Lib.Db.TvpGen -- Source Generator 단독 패키지

라이선스

MIT License

<p align="center"> Developed by <strong>김재석</strong> </p>

Product Compatible and additional computed target framework versions.
.NET 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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0 83 4/6/2026
1.1.1 111 1/9/2026
1.1.0 107 1/9/2026
1.0.0 108 12/30/2025