Now we must set up another class, which will be used to control the queries performed on the database. Add a new file called ISQLiteStorage.cs
into the Storage
folder and implement the following:
public interface ISQLiteStorage { void CreateSQLiteAsyncConnection(); Task CreateTable<T>(CancellationToken token) where T : class, IStorable, new(); Task InsertObject<T>(T item, CancellationToken token) where T : class, IStorable, new(); Task<IList<T>> GetTable<T>(CancellationToken token) where T : class, IStorable, new(); Task<T> GetObject<T>(string key, CancellationToken token) where T : class, IStorable, new(); Task ClearTable<T>(CancellationToken token) where T : class, IStorable, new(); Task DeleteObjectByKey<T>(string key, CancellationToken token) where T : class, IStorable, new(); void CloseConnection(); }
The preceding interface defines all the functions that will be executed on the database. The advantage of using SQLite is that it performs all processing asynchronously, so every function that executes an SQL query returns a task. If you look closely at the InsertObject
and DeleteObjectByKey
functions, these require a type, meaning that we can execute queries to specific tables using types.
18.219.71.21