Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -176,28 +176,11 @@ def update_record(container, updated_record):
|
|
176 |
# 🗑️ Delete record - Saying goodbye to data (it's not you, it's me)
|
177 |
def delete_record(container, id):
|
178 |
try:
|
179 |
-
|
180 |
-
|
181 |
-
doc = container.read_item(item=id, partition_key=id)
|
182 |
-
container.delete_item(item=id, partition_key=id)
|
183 |
-
return True, f"Successfully deleted record with id: {id} 🗑️"
|
184 |
-
except exceptions.CosmosResourceNotFoundError:
|
185 |
-
# Fall back to cross-partition query
|
186 |
-
query = "SELECT * FROM c WHERE c.id = @id"
|
187 |
-
params = [{"name": "@id", "value": id}]
|
188 |
-
items = list(container.query_items(
|
189 |
-
query=query,
|
190 |
-
parameters=params,
|
191 |
-
enable_cross_partition_query=True
|
192 |
-
))
|
193 |
-
|
194 |
-
if not items:
|
195 |
-
return False, f"Record with id {id} not found. 🕵️♂️"
|
196 |
-
|
197 |
-
doc = items[0]
|
198 |
-
container.delete_item(item=id, partition_key=doc['id'])
|
199 |
return True, f"Successfully deleted record with id: {id} 🗑️"
|
200 |
-
|
|
|
201 |
except exceptions.CosmosHttpResponseError as e:
|
202 |
return False, f"HTTP error occurred: {str(e)} 🚨"
|
203 |
except Exception as e:
|
|
|
176 |
# 🗑️ Delete record - Saying goodbye to data (it's not you, it's me)
|
177 |
def delete_record(container, id):
|
178 |
try:
|
179 |
+
response = container.delete_all_items_by_partition_key_stream(partition_key=id)
|
180 |
+
if response.is_successful:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
return True, f"Successfully deleted record with id: {id} 🗑️"
|
182 |
+
else:
|
183 |
+
return False, f"Failed to delete record. Status code: {response.status_code} 🚨"
|
184 |
except exceptions.CosmosHttpResponseError as e:
|
185 |
return False, f"HTTP error occurred: {str(e)} 🚨"
|
186 |
except Exception as e:
|