Python 是否将Storm实体复制到另一个存储?
我有一个模块,它使用Storm ORM将数据保存在本地SQLite数据库中。我正在开发另一个模块,该模块将数据同步到中心PostgreSQL服务器。我想我会很聪明,做以下几件事:Python 是否将Storm实体复制到另一个存储?,python,storm-orm,Python,Storm Orm,我有一个模块,它使用Storm ORM将数据保存在本地SQLite数据库中。我正在开发另一个模块,该模块将数据同步到中心PostgreSQL服务器。我想我会很聪明,做以下几件事: unsynced = localStore.find(MyType, MyType.synced == False) for assign in unsynced: self.remoteStore.add(assign) 这并不像预期的那样有效,引发了以下错误: object at 0x18bb4d0 i
unsynced = localStore.find(MyType, MyType.synced == False)
for assign in unsynced:
self.remoteStore.add(assign)
这并不像预期的那样有效,引发了以下错误:
object at 0x18bb4d0 is part of another store
是否有办法打破与本地存储的关联,以便远程保存数据?这可能会稍微复杂一些,因为在成功远程保存数据后,我需要在本地副本中翻转Synched标志。Storm中没有自动执行此操作的功能,因为应该复制什么并不总是显而易见的:
def copy(self):
"""Create a new object with the same property values."""
other = self.__class__()
# Copy over the relevant fields. If you're using an integer primary key,
# then this probably doesn't include that key.
other.foo = self.foo
other.bar = self.bar
...
return other
然后,您可以修改代码以执行以下操作:
for assign in unsynced:
self.remoteStore.add(assign.copy())