Reworking DbAccess

This commit is contained in:
Max 2023-05-29 21:26:37 +02:00
parent e0352e374c
commit ce90818e3d

View File

@ -130,6 +130,7 @@ namespace SharpRss
} }
public static async Task<FeedModel?> SetFeedsAsync(IEnumerable<FeedModel> feedModels) public static async Task<FeedModel?> SetFeedsAsync(IEnumerable<FeedModel> feedModels)
{ {
//TODO: Implement fetching system!!!
FeedModel? resultModel = null; FeedModel? resultModel = null;
await using SqliteConnection dbc = new SqliteConnection(ConnectionString); await using SqliteConnection dbc = new SqliteConnection(ConnectionString);
dbc.Open(); dbc.Open();
@ -153,7 +154,8 @@ namespace SharpRss
new SqliteParameter("lastUpdated", feedModel.LastUpdated?.ToUnixTimeMilliseconds()), new SqliteParameter("lastUpdated", feedModel.LastUpdated?.ToUnixTimeMilliseconds()),
new SqliteParameter("imageUrl", feedModel.ImageUrl ?? string.Empty), new SqliteParameter("imageUrl", feedModel.ImageUrl ?? string.Empty),
new SqliteParameter("originalDoc", feedModel.OriginalDocument ?? string.Empty) new SqliteParameter("originalDoc", feedModel.OriginalDocument ?? string.Empty)
} },
Transaction = transaction
}; };
await cmd.ExecuteNonQueryAsync(); await cmd.ExecuteNonQueryAsync();
} }
@ -225,7 +227,10 @@ namespace SharpRss
dbc.Open(); dbc.Open();
await using SqliteTransaction transaction = dbc.BeginTransaction(); await using SqliteTransaction transaction = dbc.BeginTransaction();
await using SqliteCommand cmd = new SqliteCommand($"INSERT OR REPLACE INTO {FeedItemTable} (id, feed_id, read, title, description, link, last_updated, publishing_date, author, categories, content)" + await using SqliteCommand cmd = new SqliteCommand($"INSERT OR REPLACE INTO {FeedItemTable} (id, feed_id, read, title, description, link, last_updated, publishing_date, author, categories, content)" +
$"VALUES (IFNULL((SELECT id FROM {FeedItemTable} WHERE link=@link), @id), @feedId, @read, @title, @description, @link, @lastUpdated, @publishingDate, @author, @categories, @content)", dbc); $"VALUES (IFNULL((SELECT id FROM {FeedItemTable} WHERE link=@link), @id), @feedId, @read, @title, @description, @link, @lastUpdated, @publishingDate, @author, @categories, @content)", dbc)
{
Transaction = transaction
};
foreach (FeedItemModel item in items) foreach (FeedItemModel item in items)
{ {
cmd.Parameters.Clear(); cmd.Parameters.Clear();