tiny server.
This commit is contained in:
44
App/Data/FlowerDatabase.cs
Normal file
44
App/Data/FlowerDatabase.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Blahblah.FlowerStory.Data.Model;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SQLite;
|
||||
|
||||
namespace Blahblah.FlowerStory.Data;
|
||||
|
||||
public class FlowerDatabase
|
||||
{
|
||||
private SQLiteAsyncConnection database;
|
||||
|
||||
private readonly ILogger logger;
|
||||
public FlowerDatabase(ILogger<FlowerDatabase> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
private async Task Init()
|
||||
{
|
||||
if (database is not null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
database = new SQLiteAsyncConnection(Constants.DatabasePath, Constants.Flags);
|
||||
|
||||
#if DEBUG
|
||||
var result =
|
||||
#endif
|
||||
await database.CreateTablesAsync<FlowerItem, RecordItem>();
|
||||
|
||||
#if DEBUG
|
||||
foreach (var item in result.Results)
|
||||
{
|
||||
logger.LogDebug("create table {table}, result: {result}", item.Key, item.Value);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public async Task<List<FlowerItem>> GetFlowers()
|
||||
{
|
||||
await Init();
|
||||
return await database.Table<FlowerItem>().ToListAsync();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user