Implement Storage.move.

This commit is contained in:
redxef 2022-12-06 18:14:45 +01:00
parent 4debf553e7
commit 79f88a278c
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921

View file

@ -460,7 +460,34 @@ class Storage(BaseStorage):
def move(self, item: "radicale_item.Item", to_collection: "BaseCollection", to_href: str) -> None:
pass
assert isinstance(item.collection, Collection)
assert isinstance(to_collection, Collection)
src_collection_id = item.collection._id
dst_collection_id = to_collection._id
item_table = self._meta.tables['item']
delete_stmt = sa.delete(
item_table,
).where(
sa.and_(
item_table.c.collection_id == dst_collection_id,
item_table.c.name == to_href,
)
)
update_stmt = sa.update(
item_table,
).values(
collection_id=dst_collection_id,
name=to_href,
).where(
sa.and_(
item_table.c.collection_id == src_collection_id,
item_table.c.name == item.href,
)
)
with self._engine.begin() as connection:
connection.execute(delete_stmt)
connection.execute(update_stmt)
def create_collection(
self,