Dreamine.Database.Sqlite 1.0.1
Dreamine.Database.Sqlite 데이터베이스 기능과 관련 API를 제공합니다.
로딩중...
검색중...
일치하는것 없음
SqliteDatabaseProvider.cs
이 파일의 문서화 페이지로 가기
1using Dapper;
2using Dreamine.Database.Abstractions;
3using Dreamine.Database.Core.Mapping;
4using Dreamine.Database.Core.Providers;
5using Microsoft.Data.Sqlite;
6using System.Data;
7
9
18public sealed class SqliteDatabaseProvider : DatabaseProviderBase
19{
52 public SqliteDatabaseProvider(string connectionString)
53 : base(connectionString)
54 {
55 }
56
65 public override DatabaseProviderKind Kind => DatabaseProviderKind.Sqlite;
66
107 public override bool IsTableExists(string tableName)
108 {
109 ArgumentException.ThrowIfNullOrWhiteSpace(tableName);
110
111 const string sql = "SELECT COUNT(1) FROM sqlite_master WHERE type = 'table' AND name = @TableName";
112 return ExecuteScalar<long>(sql, new { TableName = tableName }) > 0;
113 }
114
163 public override async Task<bool> IsTableExistsAsync(
164 string tableName,
165 CancellationToken cancellationToken = default)
166 {
167 ArgumentException.ThrowIfNullOrWhiteSpace(tableName);
168
169 const string sql = "SELECT COUNT(1) FROM sqlite_master WHERE type = 'table' AND name = @TableName";
170 var count = await ExecuteScalarAsync<long>(sql, new { TableName = tableName }, cancellationToken)
171 .ConfigureAwait(false);
172 return count > 0;
173 }
174
191 protected override IDbConnection CreateConnection()
192 {
193 return new SqliteConnection(ConnectionString);
194 }
195
236 protected override string QuoteIdentifier(string identifier)
237 {
238 ArgumentException.ThrowIfNullOrWhiteSpace(identifier);
239 return "\"" + identifier.Replace("\"", "\"\"", StringComparison.Ordinal) + "\"";
240 }
241
266 protected override string GetSqlType(DatabasePropertyMap property)
267 {
268 var type = property.PropertyType;
269
270 if (type == typeof(bool) ||
271 type == typeof(byte) ||
272 type == typeof(short) ||
273 type == typeof(int) ||
274 type == typeof(long))
275 {
276 return "INTEGER";
277 }
278
279 if (type == typeof(float) ||
280 type == typeof(double) ||
281 type == typeof(decimal))
282 {
283 return "REAL";
284 }
285
286 if (type == typeof(byte[]))
287 {
288 return "BLOB";
289 }
290
291 return "TEXT";
292 }
293
318 protected override string BuildPrimaryKeySql(DatabasePropertyMap property)
319 {
320 return property.IsGenerated ? " PRIMARY KEY AUTOINCREMENT" : " PRIMARY KEY";
321 }
322}
override string GetSqlType(DatabasePropertyMap property)
override string BuildPrimaryKeySql(DatabasePropertyMap property)
override async Task< bool > IsTableExistsAsync(string tableName, CancellationToken cancellationToken=default)