iconDreamine
← 목록

Dreamine.Database.SqlServer

stablev1.0.1

SQL Server 전용 드라이버 및 벌크 삽입 지원.

#database#sqlserver
TFM net8.0Package Dreamine.Database.SqlServer참조 Dreamine.Database.Abstractions, Dreamine.Database.Core

Dreamine.Database.SqlServer

Dreamine.Database.SqlServer는 Dreamine Database 패키지군의 Microsoft SQL Server Provider입니다.

English documentation

패키지 역할

이 패키지는 Microsoft.Data.SqlClient를 사용해서 SQL Server용 IDatabaseProvider를 구현합니다.

Dreamine.Database.Abstractions
        ↑
Dreamine.Database.Core
        ↑
Dreamine.Database.SqlServer

주요 기능

  • SQL Server Connection 생성
  • Bracket Identifier Quote
  • SQL Server Type Mapping
  • EnsureDatabaseExists()에서 master 접속 후 Database 생성
  • OBJECT_ID 기반 Table 생성 Guard
  • 공통 DatabaseProviderBase 기반 CRUD

빠른 시작

using Dreamine.Database.SqlServer;

var provider = new SqlServerDatabaseProvider(
    "Server=localhost;Database=dreamine_sample;User Id=sa;Password=password;TrustServerCertificate=True;");

provider.EnsureDatabaseExists();
provider.CreateTable<SampleCustomer>();
provider.Insert(new SampleCustomer
{
    Name = "Dreamine",
    Role = "Operator",
    CreatedAt = DateTime.Now
});

Database 생성 참고

EnsureDatabaseExists()master에 접속한 뒤 설정된 Database가 없으면 생성합니다. 이후 CRUD 작업은 원래 Connection String을 사용합니다.

설정한 계정에는 Database 생성 권한이 있어야 합니다. 권한이 없다면 Database를 수동으로 만든 뒤 샘플을 다시 실행하세요.

의존성

  • Dreamine.Database.Abstractions
  • Dreamine.Database.Core
  • Microsoft.Data.SqlClient

대상 프레임워크

net8.0

샘플 및 테스트

  • 단위 테스트: 20_SOURCES/200. Tests/Dreamine.FullKit.Tests/Database
  • WPF 샘플: 20_SOURCES/998. DEMO/000. Sample/010. Wpfs/SampleSmart/Pages/PageSub/PageDatabase.xaml

라이선스

MIT License

구조 다이어그램

classDiagram
    class SqlServerConnectionFactory {
        -string _connectionString
        +Create() IDbConnection
        +CreateAsync() Task~IDbConnection~
    }
    class SqlServerRepository~T~ {
        +GetAsync(int) Task~T~
        +GetAllAsync() Task~IEnumerable~T~~
        +AddAsync(T) Task
        +UpdateAsync(T) Task
        +DeleteAsync(int) Task
        -BuildInsertSql(T) string
        -BuildUpdateSql(T) string
    }
    class SqlServerUnitOfWork {
        +BeginTransaction() Task
        +CommitAsync() Task
        +RollbackAsync() Task
    }
    class SqlServerServiceExtensions {
        <<static>>
        +AddSqlServer(IServiceCollection, string) IServiceCollection
    }
    class RepositoryBase~T~ {
        <<abstract>>
    }
    RepositoryBase~T~ <|-- SqlServerRepository~T~
    SqlServerRepository~T~ --> SqlServerConnectionFactory
    SqlServerServiceExtensions --> SqlServerConnectionFactory

API 문서

타입

SqlServerDatabaseProvider

\if KO SQL Server용 Dreamine 데이터베이스 공급자 구현을 제공합니다. \endif \if EN Provides a Dreamine database-provider implementation for SQL Server. \endif

SqlServerDatabaseProvider

#ctor Method

\if KO 지정한 연결 문자열로 의 새 인스턴스를 초기화합니다. \endif \if EN Initializes a new instance with the specified connection string. \endif

connectionString— \if KO SQL Server 연결 문자열입니다. \endif \if EN The SQL Server connection string. \endif
BuildCreateTableSql Method

\if KO IDENTITY 키를 지원하는 SQL Server CREATE TABLE SQL을 만듭니다. \endif \if EN Builds SQL Server CREATE TABLE SQL with identity-key support. \endif

map— \if KO 테이블 엔터티 매핑입니다. \endif \if EN The table entity map. \endif

반환: \if KO 조건부 SQL Server CREATE TABLE SQL입니다. \endif \if EN The conditional SQL Server CREATE TABLE SQL. \endif

CreateConnection Method

\if KO 구성된 연결 문자열을 사용하는 새 SQL Server 연결을 만듭니다. \endif \if EN Creates a new SQL Server connection using the configured connection string. \endif

반환: \if KO 닫힌 SQL Server 연결입니다. \endif \if EN A closed SQL Server connection. \endif

EnsureDatabaseExists Method

\if KO 연결 문자열에 지정된 SQL Server 데이터베이스가 없으면 생성합니다. \endif \if EN Creates the SQL Server database named by the connection string when it does not exist. \endif

EnsureDatabaseExistsAsync Method

\if KO 연결 문자열에 지정된 SQL Server 데이터베이스가 없으면 비동기적으로 생성합니다. \endif \if EN Asynchronously creates the SQL Server database named by the connection string when it does not exist. \endif

cancellationToken— \if KO 작업 취소 토큰입니다. \endif \if EN A token used to cancel the operation. \endif

반환: \if KO 데이터베이스 확인 및 생성 작업입니다. \endif \if EN A task representing database verification and creation. \endif

EscapeSqlLiteral Method

\if KO SQL 문자열 리터럴에 포함될 작은따옴표를 이스케이프합니다. \endif \if EN Escapes apostrophes for inclusion in a SQL string literal. \endif

value— \if KO 이스케이프할 값입니다. \endif \if EN The value to escape. \endif

반환: \if KO 작은따옴표가 이스케이프된 값입니다. \endif \if EN The value with apostrophes escaped. \endif

GetSqlType Method

\if KO CLR 속성 형식을 대응하는 SQL Server 열 형식으로 변환합니다. \endif \if EN Converts a CLR property type to its corresponding SQL Server column type. \endif

property— \if KO 변환할 속성 매핑입니다. \endif \if EN The property mapping to convert. \endif

반환: \if KO SQL Server 열 형식 선언입니다. \endif \if EN The SQL Server column-type declaration. \endif

IsTableExists Method

\if KO 현재 SQL Server 데이터베이스에 지정한 테이블이 존재하는지 확인합니다. \endif \if EN Determines whether the specified table exists in the current SQL Server database. \endif

tableName— \if KO 확인할 테이블 이름입니다. \endif \if EN The table name to inspect. \endif

반환: \if KO 테이블 존재 여부입니다. \endif \if EN Whether the table exists. \endif

IsTableExistsAsync Method

\if KO 현재 SQL Server 데이터베이스에 지정한 테이블이 존재하는지 비동기적으로 확인합니다. \endif \if EN Asynchronously determines whether the specified table exists in the current SQL Server database. \endif

tableName— \if KO 확인할 테이블 이름입니다. \endif \if EN The table name to inspect. \endif
cancellationToken— \if KO 조회 취소 토큰입니다. \endif \if EN A token used to cancel the query. \endif

반환: \if KO 테이블 존재 여부를 결과로 제공하는 작업입니다. \endif \if EN A task whose result indicates whether the table exists. \endif

QuoteIdentifier Method

\if KO SQL Server 대괄호 문법으로 식별자를 안전하게 인용합니다. \endif \if EN Safely quotes an identifier using SQL Server bracket syntax. \endif

identifier— \if KO 인용할 식별자입니다. \endif \if EN The identifier to quote. \endif

반환: \if KO 이스케이프하고 인용한 식별자입니다. \endif \if EN The escaped and quoted identifier. \endif

Kind Property

\if KO SQL Server 공급자 종류를 가져옵니다. \endif \if EN Gets the SQL Server provider kind. \endif