Dreamine.Database.Core
Dreamine.Database.Core는 구체 Dreamine Database Provider들이 공통으로 사용하는 런타임 구현 패키지입니다.
패키지 역할
이 패키지는 Provider와 독립적인 CRUD, SQL 생성, Entity Mapping, Dapper 연동, Database Provider 기본 동작을 구현합니다.
Dreamine.Database.Abstractions
↑
Dreamine.Database.Core
↑
SQLite / MySQL / Oracle / SQL Server providers
구체 Provider는 Connection 생성, Identifier Quote, Provider별 SQL Type, Table 생성 Dialect를 제공합니다.
주요 기능
- Attribute 기반 Entity Map 생성
- 공통
DatabaseProviderBase - Dapper 기반 Command, Scalar, Query, Insert, Update, Delete
- SQL Type Mapping과 Identifier Quote를 위한 Provider별 확장 지점
- 기존 Table이 있으면 건너뛰는
CreateTable<T>()흐름 - 공통 Provider 계약의 동기/비동기 구현
Provider 확장 지점
| Member | 역할 |
|---|---|
CreateConnection() |
구체 ADO.NET Connection을 생성합니다. |
QuoteIdentifier(string) |
Provider Dialect에 맞게 Table/Column 이름을 감쌉니다. |
GetSqlType(DatabasePropertyMap) |
CLR Property Type을 Provider SQL Type으로 매핑합니다. |
BuildCreateTableSql(DatabaseEntityMap) |
Provider별 Table 생성 SQL을 만듭니다. |
ParameterPrefix |
@, : 같은 Parameter Prefix를 선택합니다. |
설계 원칙
- 공통 CRUD 동작은 한 곳에 둡니다.
- Core 패키지에는 벤더 Driver를 넣지 않습니다.
- SQL Dialect 차이는 구체 Provider 안에 가둡니다.
- 모든 Provider에서 동일한 애플리케이션 API를 유지합니다.
의존성
Dreamine.Database.AbstractionsDapper
대상 프레임워크
net8.0
관련 패키지
Dreamine.Database.AbstractionsDreamine.Database.SqliteDreamine.Database.MySqlDreamine.Database.OracleDreamine.Database.SqlServer
샘플 및 테스트
- 단위 테스트:
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 RepositoryBase~T~ {
<<abstract>>
#IDbConnectionFactory _factory
+GetAsync(int) Task~T~
+GetAllAsync() Task~IEnumerable~T~~
+FindAsync(Expression) Task~IEnumerable~T~~
+AddAsync(T) Task
+UpdateAsync(T) Task
+DeleteAsync(int) Task
}
class UnitOfWork {
-IDbConnection _conn
-IDbTransaction _tx
+BeginTransaction() Task
+CommitAsync() Task
+RollbackAsync() Task
+SaveChangesAsync() Task~int~
}
class EntityBase {
<<abstract>>
+int Id
+DateTime CreatedAt
+DateTime? UpdatedAt
}
class DbConnectionFactory {
-string _connectionString
+Create() IDbConnection
+CreateAsync() Task~IDbConnection~
}
class IRepository~T~ {
<<interface>>
}
class IUnitOfWork {
<<interface>>
}
IRepository~T~ <|.. RepositoryBase~T~
IUnitOfWork <|.. UnitOfWork
RepositoryBase~T~ --> EntityBase
RepositoryBase~T~ --> DbConnectionFactoryAPI 문서
타입
\if KO 엔터티 형식의 데이터베이스 매핑 메타데이터를 설명합니다. \endif \if EN Describes database-mapping metadata for an entity type. \endif
\if KO 엔터티 속성의 데이터베이스 매핑 메타데이터를 설명합니다. \endif \if EN Describes database-mapping metadata for an entity property. \endif
\if KO Dreamine 데이터베이스 공급자의 공통 기본 구현을 제공합니다. \endif \if EN Provides a common base implementation for Dreamine database providers. \endif
\if KO 캐시할 데이터 조작 SQL의 종류를 나타냅니다. \endif \if EN Identifies the kind of data-manipulation SQL stored in the cache. \endif
DatabaseEntityMap
\if KO 분석된 엔터티 형식과 테이블 및 속성 매핑으로 인스턴스를 초기화합니다. \endif \if EN Initializes an instance with the analyzed entity type, table, and property mappings. \endif
entityType— \if KO 매핑된 엔터티 형식입니다. \endif \if EN The mapped entity type. \endiftableName— \if KO 매핑된 테이블 이름입니다. \endif \if EN The mapped table name. \endifproperties— \if KO 엔터티의 속성 매핑 목록입니다. \endif \if EN The entity property mappings. \endif\if KO 지정한 엔터티 형식의 매핑 메타데이터를 생성하거나 캐시에서 가져옵니다. \endif \if EN Creates or retrieves cached mapping metadata for the specified entity type. \endif
entityType— \if KO 매핑할 엔터티 형식입니다. \endif \if EN The entity type to map. \endif반환: \if KO 생성되었거나 캐시된 엔터티 매핑입니다. \endif \if EN The created or cached entity map. \endif
\if KO 제네릭 엔터티 형식의 매핑 메타데이터를 생성하거나 캐시에서 가져옵니다. \endif \if EN Creates or retrieves cached mapping metadata for a generic entity type. \endif
반환: \if KO 생성되었거나 캐시된 엔터티 매핑입니다. \endif \if EN The created or cached entity map. \endif
\if KO 리플렉션을 사용하여 캐시되지 않은 새 엔터티 매핑을 만듭니다. \endif \if EN Uses reflection to create a new, uncached entity map. \endif
entityType— \if KO 분석할 엔터티 형식입니다. \endif \if EN The entity type to analyze. \endif반환: \if KO 분석된 엔터티 매핑입니다. \endif \if EN The analyzed entity map. \endif
\if KO 매핑된 엔터티 형식을 가져옵니다. \endif \if EN Gets the mapped entity type. \endif
\if KO INSERT 문에 포함할 수 있는 속성을 가져옵니다. \endif \if EN Gets the properties that can be included in INSERT statements. \endif
\if KO 존재하는 경우 매핑된 키 속성을 가져옵니다. \endif \if EN Gets the mapped key property, when one exists. \endif
\if KO 모든 매핑된 속성을 가져옵니다. \endif \if EN Gets all mapped properties. \endif
\if KO 매핑된 테이블 이름을 가져옵니다. \endif \if EN Gets the mapped table name. \endif
\if KO UPDATE 문에 포함할 수 있는 속성을 가져옵니다. \endif \if EN Gets the properties that can be included in UPDATE statements. \endif
\if KO Cache 값을 보관합니다. \endif \if EN Stores the cache value. \endif
DatabasePropertyMap
\if KO 분석된 CLR 속성과 열 매핑 정보로 인스턴스를 초기화합니다. \endif \if EN Initializes an instance with the analyzed CLR property and column-mapping information. \endif
property— \if KO 매핑된 CLR 속성입니다. \endif \if EN The mapped CLR property. \endifcolumnName— \if KO 매핑된 데이터베이스 열 이름입니다. \endif \if EN The mapped database column name. \endifisKey— \if KO 속성이 엔터티 키인지 여부입니다. \endif \if EN Whether the property is the entity key. \endifisGenerated— \if KO 값이 데이터베이스에서 생성되는지 여부입니다. \endif \if EN Whether the value is generated by the database. \endif\if KO CLR 속성의 데이터베이스 매핑 메타데이터를 만듭니다. \endif \if EN Creates database-mapping metadata for a CLR property. \endif
property— \if KO 분석할 CLR 속성입니다. \endif \if EN The CLR property to analyze. \endif반환: \if KO 분석된 속성 매핑입니다. \endif \if EN The analyzed property map. \endif
\if KO 매핑된 데이터베이스 열 이름을 가져옵니다. \endif \if EN Gets the mapped database column name. \endif
\if KO 속성 값이 데이터베이스에서 생성되는지 여부를 가져옵니다. \endif \if EN Gets whether the property value is generated by the database. \endif
\if KO 속성이 엔터티 키인지 여부를 가져옵니다. \endif \if EN Gets whether the property is the entity key. \endif
\if KO 매핑된 CLR 속성을 가져옵니다. \endif \if EN Gets the mapped CLR property. \endif
\if KO 데이터베이스 형식 매핑에 사용할 null 비허용 CLR 속성 형식을 가져옵니다. \endif \if EN Gets the non-nullable CLR property type used for database type mapping. \endif
DatabaseProviderBase
\if KO 지정한 연결 문자열로 의 새 인스턴스를 초기화합니다. \endif \if EN Initializes a new instance with the specified connection string. \endif
connectionString— \if KO 공급자가 사용할 연결 문자열입니다. \endif \if EN The connection string used by the provider. \endif\if KO 엔터티 매핑의 CREATE TABLE SQL을 만듭니다. \endif \if EN Builds CREATE TABLE SQL for an entity map. \endif
map— \if KO 테이블을 정의하는 엔터티 매핑입니다. \endif \if EN The entity map defining the table. \endif반환: \if KO CREATE TABLE SQL입니다. \endif \if EN The CREATE TABLE SQL. \endif
\if KO 엔터티 매핑의 DELETE SQL을 만듭니다. \endif \if EN Builds DELETE SQL for an entity map. \endif
map— \if KO 삭제 매핑입니다. \endif \if EN The deletion map. \endif반환: \if KO DELETE SQL입니다. \endif \if EN The DELETE SQL. \endif
\if KO 엔터티 매핑의 INSERT SQL을 만듭니다. \endif \if EN Builds INSERT SQL for an entity map. \endif
map— \if KO 삽입 매핑입니다. \endif \if EN The insertion map. \endif반환: \if KO INSERT SQL입니다. \endif \if EN The INSERT SQL. \endif
\if KO 기본 키 열에 덧붙일 공급자별 SQL 조각을 만듭니다. \endif \if EN Builds the provider-specific SQL fragment appended to a primary-key column. \endif
property— \if KO 기본 키 속성 매핑입니다. \endif \if EN The primary-key property mapping. \endif반환: \if KO 기본 키 SQL 조각입니다. \endif \if EN The primary-key SQL fragment. \endif
\if KO 엔터티 매핑의 UPDATE SQL을 만듭니다. \endif \if EN Builds UPDATE SQL for an entity map. \endif
map— \if KO 갱신 매핑입니다. \endif \if EN The update map. \endif반환: \if KO UPDATE SQL입니다. \endif \if EN The UPDATE SQL. \endif
\if KO 공급자별 닫힌 데이터베이스 연결을 만듭니다. \endif \if EN Creates a provider-specific closed database connection. \endif
반환: \if KO 새 데이터베이스 연결입니다. \endif \if EN A new database connection. \endif
\if KO 새 공급자 연결을 만들고 동기적으로 엽니다. \endif \if EN Creates and synchronously opens a new provider connection. \endif
반환: \if KO 열린 데이터베이스 연결입니다. \endif \if EN The opened database connection. \endif
\if KO 에 매핑된 테이블이 없으면 생성합니다. \endif \if EN Creates the table mapped to when it does not exist. \endif
\if KO 에 매핑된 테이블이 없으면 비동기적으로 생성합니다. \endif \if EN Asynchronously creates the table mapped to when it does not exist. \endif
cancellationToken— \if KO 생성 작업 취소 토큰입니다. \endif \if EN A token used to cancel table creation. \endif반환: \if KO 테이블 확인 및 생성 작업입니다. \endif \if EN A task representing table verification and creation. \endif
\if KO 키로 식별된 엔터티 행을 삭제합니다. \endif \if EN Deletes the entity row identified by its key. \endif
entity— \if KO 삭제할 엔터티입니다. \endif \if EN The entity to delete. \endif반환: \if KO 행이 삭제되었는지 여부입니다. \endif \if EN Whether a row was deleted. \endif
\if KO 키로 식별된 엔터티 행을 비동기적으로 삭제합니다. \endif \if EN Asynchronously deletes the entity row identified by its key. \endif
entity— \if KO 삭제할 엔터티입니다. \endif \if EN The entity to delete. \endifcancellationToken— \if KO 삭제 취소 토큰입니다. \endif \if EN A token used to cancel deletion. \endif반환: \if KO 행 삭제 여부를 결과로 제공하는 작업입니다. \endif \if EN A task whose result indicates whether a row was deleted. \endif
\if KO 대상 데이터베이스를 열어 존재 여부를 동기적으로 확인합니다. \endif \if EN Synchronously verifies the target database by opening it. \endif
\if KO 대상 데이터베이스를 열어 존재 여부를 비동기적으로 확인합니다. \endif \if EN Asynchronously verifies the target database by opening it. \endif
cancellationToken— \if KO 열기 작업 취소 토큰입니다. \endif \if EN A token used to cancel the open operation. \endif반환: \if KO 데이터베이스 확인 작업입니다. \endif \if EN A task representing the database verification. \endif
\if KO 결과 집합을 반환하지 않는 SQL 명령을 동기적으로 실행합니다. \endif \if EN Synchronously executes a SQL command that does not return a result set. \endif
sql— \if KO 실행할 SQL입니다. \endif \if EN The SQL to execute. \endifparameters— \if KO 선택적 SQL 매개 변수 객체입니다. \endif \if EN The optional SQL-parameter object. \endif반환: \if KO 영향을 받은 행 수입니다. \endif \if EN The number of affected rows. \endif
\if KO 결과 집합을 반환하지 않는 SQL 명령을 비동기적으로 실행합니다. \endif \if EN Asynchronously executes a SQL command that does not return a result set. \endif
sql— \if KO 실행할 SQL입니다. \endif \if EN The SQL to execute. \endifparameters— \if KO 선택적 SQL 매개 변수 객체입니다. \endif \if EN The optional SQL-parameter object. \endifcancellationToken— \if KO 실행 취소 토큰입니다. \endif \if EN A token used to cancel execution. \endif반환: \if KO 영향을 받은 행 수를 결과로 제공하는 작업입니다. \endif \if EN A task whose result is the number of affected rows. \endif
\if KO SQL 명령을 실행하고 첫 번째 스칼라 값을 반환합니다. \endif \if EN Executes a SQL command and returns its first scalar value. \endif
sql— \if KO 실행할 SQL입니다. \endif \if EN The SQL to execute. \endifparameters— \if KO 선택적 SQL 매개 변수 객체입니다. \endif \if EN The optional SQL-parameter object. \endif반환: \if KO 변환된 스칼라 값입니다. \endif \if EN The converted scalar value. \endif
\if KO SQL 명령을 비동기적으로 실행하고 첫 번째 스칼라 값을 반환합니다. \endif \if EN Asynchronously executes a SQL command and returns its first scalar value. \endif
sql— \if KO 실행할 SQL입니다. \endif \if EN The SQL to execute. \endifparameters— \if KO 선택적 SQL 매개 변수 객체입니다. \endif \if EN The optional SQL-parameter object. \endifcancellationToken— \if KO 실행 취소 토큰입니다. \endif \if EN A token used to cancel execution. \endif반환: \if KO 변환된 스칼라 값을 결과로 제공하는 작업입니다. \endif \if EN A task whose result is the converted scalar value. \endif
\if KO 데이터 조작 SQL을 캐시에서 가져오거나 생성합니다. \endif \if EN Retrieves data-manipulation SQL from the cache or builds it. \endif
kind— \if KO 필요한 SQL 작업 종류입니다. \endif \if EN The required SQL operation kind. \endif반환: \if KO 캐시되었거나 새로 생성된 SQL입니다. \endif \if EN The cached or newly built SQL. \endif
\if KO 속성 매핑에 대응하는 공급자별 SQL 열 형식을 반환합니다. \endif \if EN Returns the provider-specific SQL column type for a property mapping. \endif
property— \if KO 변환할 속성 매핑입니다. \endif \if EN The property mapping to convert. \endif반환: \if KO SQL 열 형식 선언입니다. \endif \if EN The SQL column-type declaration. \endif
\if KO 엔터티를 삽입합니다. \endif \if EN Inserts an entity. \endif
entity— \if KO 삽입할 엔터티입니다. \endif \if EN The entity to insert. \endif반환: \if KO 행이 삽입되었는지 여부입니다. \endif \if EN Whether a row was inserted. \endif
\if KO 엔터티를 비동기적으로 삽입합니다. \endif \if EN Asynchronously inserts an entity. \endif
entity— \if KO 삽입할 엔터티입니다. \endif \if EN The entity to insert. \endifcancellationToken— \if KO 삽입 취소 토큰입니다. \endif \if EN A token used to cancel insertion. \endif반환: \if KO 행 삽입 여부를 결과로 제공하는 작업입니다. \endif \if EN A task whose result indicates whether a row was inserted. \endif
\if KO 지정한 이름의 테이블이 존재하는지 확인합니다. \endif \if EN Determines whether a table with the specified name exists. \endif
tableName— \if KO 확인할 테이블 이름입니다. \endif \if EN The table name to inspect. \endif반환: \if KO 테이블 존재 여부입니다. \endif \if EN Whether the table exists. \endif
\if KO 에 매핑된 테이블이 존재하는지 확인합니다. \endif \if EN Determines whether the table mapped to exists. \endif
반환: \if KO 테이블 존재 여부입니다. \endif \if EN Whether the table exists. \endif
\if KO 지정한 이름의 테이블이 존재하는지 비동기적으로 확인합니다. \endif \if EN Asynchronously determines whether a table with the specified name exists. \endif
tableName— \if KO 확인할 테이블 이름입니다. \endif \if EN The table name to inspect. \endifcancellationToken— \if KO 확인 작업 취소 토큰입니다. \endif \if EN A token used to cancel the inspection. \endif반환: \if KO 테이블 존재 여부를 결과로 제공하는 작업입니다. \endif \if EN A task whose result indicates whether the table exists. \endif
\if KO 에 매핑된 테이블이 존재하는지 비동기적으로 확인합니다. \endif \if EN Asynchronously determines whether the table mapped to exists. \endif
cancellationToken— \if KO 확인 작업 취소 토큰입니다. \endif \if EN A token used to cancel the inspection. \endif반환: \if KO 테이블 존재 여부를 결과로 제공하는 작업입니다. \endif \if EN A task whose result indicates whether the table exists. \endif
\if KO 가능한 경우 비동기 API로 데이터베이스 연결을 엽니다. \endif \if EN Opens a database connection using an asynchronous API when available. \endif
connection— \if KO 열 데이터베이스 연결입니다. \endif \if EN The database connection to open. \endifcancellationToken— \if KO 열기 취소 토큰입니다. \endif \if EN A token used to cancel opening. \endif반환: \if KO 연결 열기 작업입니다. \endif \if EN A task representing connection opening. \endif
\if KO SQL 조회를 실행하고 행을 로 매핑합니다. \endif \if EN Executes a SQL query and maps its rows to . \endif
sql— \if KO 실행할 SQL 조회문입니다. \endif \if EN The SQL query to execute. \endifparameters— \if KO 선택적 조회 매개 변수 객체입니다. \endif \if EN The optional query-parameter object. \endif반환: \if KO 메모리에 구체화된 매핑 행 시퀀스입니다. \endif \if EN A materialized sequence of mapped rows. \endif
\if KO SQL 조회를 비동기적으로 실행하고 행을 로 매핑합니다. \endif \if EN Asynchronously executes a SQL query and maps its rows to . \endif
sql— \if KO 실행할 SQL 조회문입니다. \endif \if EN The SQL query to execute. \endifparameters— \if KO 선택적 조회 매개 변수 객체입니다. \endif \if EN The optional query-parameter object. \endifcancellationToken— \if KO 조회 취소 토큰입니다. \endif \if EN A token used to cancel the query. \endif반환: \if KO 매핑된 행의 읽기 전용 목록을 결과로 제공하는 작업입니다. \endif \if EN A task whose result is a read-only list of mapped rows. \endif
\if KO 공급자 문법에 맞게 SQL 식별자를 인용합니다. \endif \if EN Quotes a SQL identifier using provider syntax. \endif
identifier— \if KO 인용할 식별자입니다. \endif \if EN The identifier to quote. \endif반환: \if KO 인용된 식별자입니다. \endif \if EN The quoted identifier. \endif
\if KO 엔터티 매핑에서 필수 키 속성을 가져옵니다. \endif \if EN Gets the required key property from an entity map. \endif
map— \if KO 검사할 엔터티 매핑입니다. \endif \if EN The entity map to inspect. \endif반환: \if KO 매핑된 키 속성입니다. \endif \if EN The mapped key property. \endif
\if KO 키로 식별된 엔터티 행을 갱신합니다. \endif \if EN Updates the entity row identified by its key. \endif
entity— \if KO 갱신할 엔터티입니다. \endif \if EN The entity to update. \endif반환: \if KO 행이 갱신되었는지 여부입니다. \endif \if EN Whether a row was updated. \endif
\if KO 키로 식별된 엔터티 행을 비동기적으로 갱신합니다. \endif \if EN Asynchronously updates the entity row identified by its key. \endif
entity— \if KO 갱신할 엔터티입니다. \endif \if EN The entity to update. \endifcancellationToken— \if KO 갱신 취소 토큰입니다. \endif \if EN A token used to cancel the update. \endif반환: \if KO 행 갱신 여부를 결과로 제공하는 작업입니다. \endif \if EN A task whose result indicates whether a row was updated. \endif
\if KO 데이터베이스 연결 문자열을 가져옵니다. \endif \if EN Gets the database connection string. \endif
\if KO 구현 공급자의 종류를 가져옵니다. \endif \if EN Gets the concrete provider kind. \endif
\if KO SQL 매개 변수 이름 앞에 붙는 공급자별 접두사를 가져옵니다. \endif \if EN Gets the provider-specific prefix placed before SQL parameter names. \endif
\if KO Sql Cache 값을 보관합니다. \endif \if EN Stores the sql cache value. \endif
SqlKind
\if KO 삭제 SQL입니다. \endif \if EN Delete SQL. \endif
\if KO 삽입 SQL입니다. \endif \if EN Insert SQL. \endif
\if KO 갱신 SQL입니다. \endif \if EN Update SQL. \endif