diff --git a/src/Speckle.Sdk/SQLite/SQLiteJsonCacheManager.cs b/src/Speckle.Sdk/SQLite/SQLiteJsonCacheManager.cs index 9cd7a98c..8ffffddd 100644 --- a/src/Speckle.Sdk/SQLite/SQLiteJsonCacheManager.cs +++ b/src/Speckle.Sdk/SQLite/SQLiteJsonCacheManager.cs @@ -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); diff --git a/src/Speckle.Sdk/Serialisation/V2/DummySendServerObjectManager.cs b/src/Speckle.Sdk/Serialisation/V2/DummySendServerObjectManager.cs index 950a8667..827ed34a 100644 --- a/src/Speckle.Sdk/Serialisation/V2/DummySendServerObjectManager.cs +++ b/src/Speckle.Sdk/Serialisation/V2/DummySendServerObjectManager.cs @@ -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(); diff --git a/tests/Speckle.Sdk.Serialization.Tests/DetachedTests.cs b/tests/Speckle.Sdk.Serialization.Tests/DetachedTests.cs index c48021f1..a226c956 100644 --- a/tests/Speckle.Sdk.Serialization.Tests/DetachedTests.cs +++ b/tests/Speckle.Sdk.Serialization.Tests/DetachedTests.cs @@ -380,6 +380,8 @@ public class DummySendCacheManager(Dictionary 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) diff --git a/tests/Speckle.Sdk.Serialization.Tests/DummySqLiteReceiveManager.cs b/tests/Speckle.Sdk.Serialization.Tests/DummySqLiteReceiveManager.cs index cdf25af7..42961d6b 100644 --- a/tests/Speckle.Sdk.Serialization.Tests/DummySqLiteReceiveManager.cs +++ b/tests/Speckle.Sdk.Serialization.Tests/DummySqLiteReceiveManager.cs @@ -12,6 +12,8 @@ public class DummySqLiteReceiveManager(Dictionary 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(); diff --git a/tests/Speckle.Sdk.Serialization.Tests/DummySqLiteSendManager.cs b/tests/Speckle.Sdk.Serialization.Tests/DummySqLiteSendManager.cs index eb8780c0..ce1dae8c 100644 --- a/tests/Speckle.Sdk.Serialization.Tests/DummySqLiteSendManager.cs +++ b/tests/Speckle.Sdk.Serialization.Tests/DummySqLiteSendManager.cs @@ -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();