Dreamine.Database.MySql
Dreamine.Database.MySql은 Dreamine Database 패키지군의 MySQL Provider입니다.
패키지 역할
이 패키지는 MySqlConnector를 사용해서 MySQL용 IDatabaseProvider를 구현합니다.
Dreamine.Database.Abstractions
↑
Dreamine.Database.Core
↑
Dreamine.Database.MySql
주요 기능
- MySQL Connection 생성
- Backtick Identifier Quote
- MySQL Type Mapping
EnsureDatabaseExists()에서CREATE DATABASE IF NOT EXISTS수행CREATE TABLE IF NOT EXISTSTable 생성- 공통
DatabaseProviderBase기반 CRUD
빠른 시작
using Dreamine.Database.MySql;
var provider = new MySqlDatabaseProvider(
"Server=localhost;Port=3306;Database=dreamine_sample;User ID=root;Password=1234;");
provider.EnsureDatabaseExists();
provider.CreateTable<SampleCustomer>();
provider.Insert(new SampleCustomer
{
Name = "Dreamine",
Role = "Operator",
CreatedAt = DateTime.Now
});
Database 생성 참고
EnsureDatabaseExists()는 선택된 Database 없이 MySQL 서버에 접속한 뒤 Database가 없으면 생성합니다. 이후 CRUD 작업은 원래 Connection String을 사용합니다.
설정한 계정에는 Database 생성 권한이 있어야 합니다. 권한이 없다면 Database를 수동으로 만든 뒤 샘플을 다시 실행하세요.
의존성
Dreamine.Database.AbstractionsDreamine.Database.CoreMySqlConnector
대상 프레임워크
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 MySqlConnectionFactory {
-string _connectionString
+Create() IDbConnection
+CreateAsync() Task~IDbConnection~
}
class MySqlRepository~T~ {
+GetAsync(int) Task~T~
+GetAllAsync() Task~IEnumerable~T~~
+AddAsync(T) Task
+UpdateAsync(T) Task
+DeleteAsync(int) Task
}
class MySqlUnitOfWork {
+BeginTransaction() Task
+CommitAsync() Task
+RollbackAsync() Task
}
class MySqlServiceExtensions {
<<static>>
+AddMySql(IServiceCollection, string) IServiceCollection
}
class RepositoryBase~T~ {
<<abstract>>
}
RepositoryBase~T~ <|-- MySqlRepository~T~
MySqlRepository~T~ --> MySqlConnectionFactoryAPI 문서
타입
\if KO MySQL용 Dreamine 데이터베이스 공급자 구현을 제공합니다. \endif \if EN Provides a Dreamine database-provider implementation for MySQL. \endif
MySqlDatabaseProvider
\if KO 지정한 연결 문자열로 의 새 인스턴스를 초기화합니다. \endif \if EN Initializes a new instance with the specified connection string. \endif
connectionString— \if KO MySQL 연결 문자열입니다. \endif \if EN The MySQL connection string. \endif\if KO 자동 증가 키를 지원하는 MySQL CREATE TABLE SQL을 만듭니다. \endif \if EN Builds MySQL CREATE TABLE SQL with auto-increment key support. \endif
map— \if KO 테이블 엔터티 매핑입니다. \endif \if EN The table entity map. \endif반환: \if KO MySQL CREATE TABLE SQL입니다. \endif \if EN The MySQL CREATE TABLE SQL. \endif
\if KO 구성된 연결 문자열을 사용하는 새 MySQL 연결을 만듭니다. \endif \if EN Creates a new MySQL connection using the configured connection string. \endif
반환: \if KO 닫힌 MySQL 연결입니다. \endif \if EN A closed MySQL connection. \endif
\if KO 연결 문자열에 지정된 MySQL 데이터베이스가 없으면 생성합니다. \endif \if EN Creates the MySQL database named by the connection string when it does not exist. \endif
\if KO 연결 문자열에 지정된 MySQL 데이터베이스가 없으면 비동기적으로 생성합니다. \endif \if EN Asynchronously creates the MySQL 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
\if KO CLR 속성 형식을 대응하는 MySQL 열 형식으로 변환합니다. \endif \if EN Converts a CLR property type to its corresponding MySQL column type. \endif
property— \if KO 변환할 속성 매핑입니다. \endif \if EN The property mapping to convert. \endif반환: \if KO MySQL 열 형식 선언입니다. \endif \if EN The MySQL column-type declaration. \endif
\if KO 현재 MySQL 데이터베이스에 지정한 테이블이 존재하는지 확인합니다. \endif \if EN Determines whether the specified table exists in the current MySQL database. \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 현재 MySQL 데이터베이스에 지정한 테이블이 존재하는지 비동기적으로 확인합니다. \endif \if EN Asynchronously determines whether the specified table exists in the current MySQL database. \endif
tableName— \if KO 확인할 테이블 이름입니다. \endif \if EN The table name to inspect. \endifcancellationToken— \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
\if KO MySQL 백틱 문법으로 식별자를 안전하게 인용합니다. \endif \if EN Safely quotes an identifier using MySQL backtick syntax. \endif
identifier— \if KO 인용할 식별자입니다. \endif \if EN The identifier to quote. \endif반환: \if KO 이스케이프하고 인용한 식별자입니다. \endif \if EN The escaped and quoted identifier. \endif
\if KO MySQL 공급자 종류를 가져옵니다. \endif \if EN Gets the MySQL provider kind. \endif