Skip to content

Commit 82a4922

Browse files
committed
Add Clear & DropAndCreate methods
1 parent c9e7119 commit 82a4922

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/NoSQLite/NoSQLiteConnection.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ private void SetJournalMode() =>
122122
/// </summary>
123123
public JsonSerializerOptions? JsonOptions { get; set; }
124124

125+
/// <summary>
126+
/// Deletes all rows from a table.
127+
/// </summary>
128+
public void Clear()
129+
{
130+
sqlite3_exec(db, $"DELETE FROM {Table};");
131+
}
132+
133+
/// <summary>
134+
/// Drops the table and then Creates it again. This will delete all indexes views etc.
135+
/// </summary>
136+
/// <remarks>See <see href="https://sqlite.org/lang_droptable.html"/> for more info.</remarks>
137+
public void DropAndCreate()
138+
{
139+
sqlite3_exec(db, $"DROP TABLE IF EXISTS {Table};");
140+
var result = CreateTable();
141+
142+
db.CheckResult(result, $"Could not create '{Table}' database table");
143+
}
144+
125145
#region Find
126146

127147
private readonly Lazy<SQLiteStmt> existsStmt;

0 commit comments

Comments
 (0)