Skip to content

Commit 8796754

Browse files
committed
Replace CreateTableResult with bool
1 parent 664b001 commit 8796754

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

SQLiteSharp/Enums.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
namespace SQLiteSharp;
22

3-
public enum CreateTableResult {
4-
Created,
5-
Migrated,
6-
}
7-
83
public static class CollationType {
94
/// <summary>
105
/// Compares the strings for an exact match (case-sensitive).

SQLiteSharp/SQLiteConnection.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ public TableMap MapTable<T>() {
120120
/// For example, passing "fts5" creates a virtual table using <see href="https://www.sql-easy.com/learn/sqlite-full-text-search">Full Text Search v5</see>.
121121
/// </summary>
122122
/// <returns>
123-
/// Whether the table was created or migrated.
123+
/// <see langword="true"/> if the table was created, <see langword="false"/> if it was migrated.
124124
/// </returns>
125-
public CreateTableResult CreateTable(Type type, string? virtualModuleName = null) {
125+
public bool CreateTable(Type type, string? virtualModuleName = null) {
126126
TableMap map = MapTable(type);
127127

128128
// Ensure table has at least one column
@@ -131,11 +131,12 @@ public CreateTableResult CreateTable(Type type, string? virtualModuleName = null
131131
}
132132

133133
// Check if the table already exists
134-
CreateTableResult result = CreateTableResult.Created;
134+
bool created;
135135
List<ColumnInfo> existingColumns = GetColumnInfos(map.TableName).ToList();
136136

137137
// Create new table
138138
if (existingColumns.Count == 0) {
139+
created = true;
139140
// Add virtual table modifiers
140141
string virtualModifier = virtualModuleName is not null ? "virtual" : "";
141142
string usingModifier = virtualModuleName is not null ? $"using {Quote(virtualModuleName)}" : "";
@@ -153,7 +154,7 @@ public CreateTableResult CreateTable(Type type, string? virtualModuleName = null
153154
}
154155
// Migrate existing table
155156
else {
156-
result = CreateTableResult.Migrated;
157+
created = false;
157158
MigrateTable(map);
158159
}
159160

@@ -184,21 +185,21 @@ public CreateTableResult CreateTable(Type type, string? virtualModuleName = null
184185
CreateIndex(index.IndexName, index.TableName, index.Columns, index.Unique);
185186
}
186187

187-
return result;
188+
return created;
188189
}
189190
/// <inheritdoc cref="CreateTable(Type, string?)"/>
190-
public CreateTableResult CreateTable<T>(string? virtualModuleName = null) {
191+
public bool CreateTable<T>(string? virtualModuleName = null) {
191192
return CreateTable(typeof(T), virtualModuleName);
192193
}
193194
/// <summary>
194195
/// Creates tables for the given types if they don't already exist.<br/>
195196
/// Indexes are also created for columns with <see cref="IndexedAttribute"/>.
196197
/// </summary>
197198
/// <returns>
198-
/// Whether the tables were created or migrated.
199+
/// <see langword="true"/> if the tables were created, <see langword="false"/> if they were migrated.
199200
/// </returns>
200-
public Dictionary<Type, CreateTableResult> CreateTables(IEnumerable<Type> types) {
201-
Dictionary<Type, CreateTableResult> results = [];
201+
public Dictionary<Type, bool> CreateTables(IEnumerable<Type> types) {
202+
Dictionary<Type, bool> results = [];
202203
foreach (Type type in types) {
203204
results[type] = CreateTable(type);
204205
}
@@ -808,15 +809,15 @@ public Task<TableMap> GetMappingAsync(Type type) {
808809
return Task.Run(() => MapTable<T>());
809810
}
810811
/// <inheritdoc cref="CreateTable(Type, string?)"/>
811-
public Task<CreateTableResult> CreateTableAsync(Type type, string? virtualModuleName = null) {
812+
public Task<bool> CreateTableAsync(Type type, string? virtualModuleName = null) {
812813
return Task.Run(() => CreateTable(type, virtualModuleName));
813814
}
814815
/// <inheritdoc cref="CreateTable{T}(string?)"/>
815-
public Task<CreateTableResult> CreateTableAsync<T>(string? virtualModuleName = null) where T : new() {
816+
public Task<bool> CreateTableAsync<T>(string? virtualModuleName = null) where T : new() {
816817
return Task.Run(() => CreateTable<T>(virtualModuleName));
817818
}
818819
/// <inheritdoc cref="CreateTables(IEnumerable{Type})"/>
819-
public Task<Dictionary<Type, CreateTableResult>> CreateTablesAsync(IEnumerable<Type> types) {
820+
public Task<Dictionary<Type, bool>> CreateTablesAsync(IEnumerable<Type> types) {
820821
return Task.Run(() => CreateTables(types));
821822
}
822823
/// <inheritdoc cref="DropTable{T}()"/>

0 commit comments

Comments
 (0)