tiny server.

This commit is contained in:
2023-05-23 08:37:20 +08:00
parent 78a5d8d3fa
commit c8bf017a70
50 changed files with 1242 additions and 32 deletions

View 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();
}
}