Add method to replace in sqlite (#190)
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user