Add method to replace in sqlite (#190)

This commit is contained in:
Adam Hathcock
2024-12-16 12:01:53 +00:00
committed by GitHub
parent defcee165a
commit 675d896e0d
5 changed files with 21 additions and 0 deletions
@@ -96,6 +96,7 @@ public class SqLiteJsonCacheManager : ISqLiteJsonCacheManager
return null; // pass on the duty of null checks to consumers
}
//This does an insert or ignores if already exists
public void SaveObject(string id, string json)
{
using var c = new SqliteConnection(_connectionString);
@@ -108,6 +109,18 @@ public class SqLiteJsonCacheManager : ISqLiteJsonCacheManager
command.ExecuteNonQuery();
}
//This does an insert or replaces if already exists
public void UpdateObject(string id, string json)
{
using var c = new SqliteConnection(_connectionString);
c.Open();
const string COMMAND_TEXT = "REPLACE INTO objects(hash, content) VALUES(@hash, @content)";
using var command = new SqliteCommand(COMMAND_TEXT, c);
command.Parameters.AddWithValue("@hash", id);
command.Parameters.AddWithValue("@content", json);
command.ExecuteNonQuery();
}
public void SaveObjects(IEnumerable<(string id, string json)> items)
{
using var c = new SqliteConnection(_connectionString);
@@ -15,6 +15,8 @@ public class DummySqLiteJsonCacheManager : ISqLiteJsonCacheManager
public void SaveObject(string id, string json) => throw new NotImplementedException();
public void UpdateObject(string id, string json) => throw new NotImplementedException();
public void SaveObjects(IEnumerable<(string id, string json)> items) => throw new NotImplementedException();
public bool HasObject(string objectId) => throw new NotImplementedException();
@@ -380,6 +380,8 @@ public class DummySendCacheManager(Dictionary<string, string> objects) : ISqLite
public void SaveObject(string id, string json) => throw new NotImplementedException();
public void UpdateObject(string id, string json) => throw new NotImplementedException();
public bool HasObject(string objectId) => false;
public void SaveObjects(IEnumerable<(string id, string json)> items)
@@ -12,6 +12,8 @@ public class DummySqLiteReceiveManager(Dictionary<string, string> savedObjects)
public void SaveObject(string id, string json) => throw new NotImplementedException();
public void UpdateObject(string id, string json) => throw new NotImplementedException();
public void SaveObjects(IEnumerable<(string id, string json)> items) => throw new NotImplementedException();
public bool HasObject(string objectId) => throw new NotImplementedException();
@@ -8,6 +8,8 @@ public class DummySqLiteSendManager : ISqLiteJsonCacheManager
public void SaveObject(string id, string json) => throw new NotImplementedException();
public void UpdateObject(string id, string json) => throw new NotImplementedException();
public void SaveObjects(IEnumerable<(string id, string json)> items) => throw new NotImplementedException();
public bool HasObject(string objectId) => throw new NotImplementedException();