26 lines
640 B
C#
26 lines
640 B
C#
using SQLite;
|
|
using cfs_tracker.Models;
|
|
|
|
namespace cfs_tracker.Data;
|
|
|
|
public class AppDatabase
|
|
{
|
|
private SQLiteAsyncConnection? _database;
|
|
private bool _initialized;
|
|
|
|
public async Task InitAsync()
|
|
{
|
|
if (_initialized)
|
|
return;
|
|
|
|
var dbPath = Path.Combine(FileSystem.Current.AppDataDirectory, "mecfs_tracker.db3");
|
|
|
|
_database = new SQLiteAsyncConnection(dbPath);
|
|
await _database.CreateTableAsync<HealthEntry>();
|
|
|
|
_initialized = true;
|
|
}
|
|
|
|
public SQLiteAsyncConnection Connection =>
|
|
_database ?? throw new InvalidOperationException("Database not initialized.");
|
|
} |