Skip to content

Commit d467b26

Browse files
committed
Merge pull request oysteinkrog#174 from kreuzhofer/master
Create non generic versions of DeleteAll and DropTable methods
2 parents 50df1a2 + 086c054 commit d467b26

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/SQLite.Net.Async/SQLiteAsyncConnection.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,19 @@ public Task<CreateTablesResult> CreateTablesAsync([NotNull] params Type[] types)
141141
[PublicAPI]
142142
public Task<int> DropTableAsync<T>(CancellationToken cancellationToken = default (CancellationToken))
143143
where T : class
144+
{
145+
return DropTableAsync(typeof (T), cancellationToken);
146+
}
147+
148+
[PublicAPI]
149+
public Task<int> DropTableAsync(Type t, CancellationToken cancellationToken = default (CancellationToken))
144150
{
145151
return Task.Factory.StartNew(() =>
146152
{
147153
var conn = GetConnection();
148154
using (conn.Lock())
149155
{
150-
return conn.DropTable<T>();
156+
return conn.DropTable(t);
151157
}
152158
}, cancellationToken, _taskCreationOptions, _taskScheduler ?? TaskScheduler.Default);
153159
}
@@ -222,13 +228,19 @@ public Task<CreateTablesResult> CreateTablesAsync([NotNull] params Type[] types)
222228

223229
[PublicAPI]
224230
public Task<int> DeleteAllAsync<T>(CancellationToken cancellationToken = default (CancellationToken))
231+
{
232+
return DeleteAllAsync(typeof(T), cancellationToken);
233+
}
234+
235+
[PublicAPI]
236+
public Task<int> DeleteAllAsync(Type t, CancellationToken cancellationToken = default (CancellationToken))
225237
{
226238
return Task.Factory.StartNew(() =>
227239
{
228240
var conn = GetConnection();
229241
using (conn.Lock())
230242
{
231-
return conn.DeleteAll<T>();
243+
return conn.DeleteAll(t);
232244
}
233245
}, cancellationToken, _taskCreationOptions, _taskScheduler ?? TaskScheduler.Default);
234246
}

src/SQLite.Net/SQLiteConnection.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,16 @@ public TableMapping GetMapping<T>()
324324
[PublicAPI]
325325
public int DropTable<T>()
326326
{
327-
var map = GetMapping(typeof (T));
327+
return DropTable(typeof (T));
328+
}
329+
330+
/// <summary>
331+
/// Executes a "drop table" on the database. This is non-recoverable.
332+
/// </summary>
333+
[PublicAPI]
334+
public int DropTable(Type t)
335+
{
336+
var map = GetMapping(t);
328337

329338
var query = string.Format("drop table if exists \"{0}\"", map.TableName);
330339

@@ -1674,7 +1683,24 @@ public int Delete<T>(object primaryKey)
16741683
[PublicAPI]
16751684
public int DeleteAll<T>()
16761685
{
1677-
var map = GetMapping(typeof (T));
1686+
return DeleteAll(typeof (T));
1687+
}
1688+
1689+
/// <summary>
1690+
/// Deletes all the objects from the specified table.
1691+
/// WARNING WARNING: Let me repeat. It deletes ALL the objects from the
1692+
/// specified table. Do you really want to do that?
1693+
/// </summary>
1694+
/// <returns>
1695+
/// The number of objects deleted.
1696+
/// </returns>
1697+
/// <typeparam name='T'>
1698+
/// The type of objects to delete.
1699+
/// </typeparam>
1700+
[PublicAPI]
1701+
public int DeleteAll(Type t)
1702+
{
1703+
var map = GetMapping(t);
16781704
var query = string.Format("delete from \"{0}\"", map.TableName);
16791705
return Execute(query);
16801706
}

0 commit comments

Comments
 (0)