Insert or update a wiki node and optionally refresh its Markdown mirror.
(
*,
user_id: str,
node_id: str,
node_type: str,
title: str,
body: str,
metadata: Optional[Dict[str, Any]] = None,
keywords: Optional[str] = None,
source_type: Optional[str] = None,
source_ref: Optional[str] = None,
file_path: Optional[str] = None,
write_mirror: bool = True,
)
| 286 | |
| 287 | |
| 288 | def upsert_node( |
| 289 | *, |
| 290 | user_id: str, |
| 291 | node_id: str, |
| 292 | node_type: str, |
| 293 | title: str, |
| 294 | body: str, |
| 295 | metadata: Optional[Dict[str, Any]] = None, |
| 296 | keywords: Optional[str] = None, |
| 297 | source_type: Optional[str] = None, |
| 298 | source_ref: Optional[str] = None, |
| 299 | file_path: Optional[str] = None, |
| 300 | write_mirror: bool = True, |
| 301 | ) -> Dict[str, Any]: |
| 302 | """Insert or update a wiki node and optionally refresh its Markdown mirror.""" |
| 303 | init_wiki_schema() |
| 304 | now = _now() |
| 305 | relative_path = file_path or _relative_file_path(user_id, node_type, node_id) |
| 306 | conn = db_ops.get_connection() |
| 307 | cursor = conn.cursor() |
| 308 | cursor.execute( |
| 309 | """ |
| 310 | INSERT INTO wiki_nodes |
| 311 | (node_id, user_id, node_type, title, body, metadata_json, |
| 312 | keywords, file_path, source_type, source_ref, created_at, updated_at) |
| 313 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
| 314 | ON CONFLICT(user_id, node_id) DO UPDATE SET |
| 315 | node_type=excluded.node_type, |
| 316 | title=excluded.title, |
| 317 | body=excluded.body, |
| 318 | metadata_json=excluded.metadata_json, |
| 319 | keywords=excluded.keywords, |
| 320 | file_path=excluded.file_path, |
| 321 | source_type=excluded.source_type, |
| 322 | source_ref=excluded.source_ref, |
| 323 | updated_at=excluded.updated_at |
| 324 | """, |
| 325 | ( |
| 326 | node_id, |
| 327 | user_id, |
| 328 | node_type, |
| 329 | title or node_id, |
| 330 | body or "", |
| 331 | _json_dumps(metadata), |
| 332 | keywords or "", |
| 333 | relative_path, |
| 334 | source_type, |
| 335 | source_ref, |
| 336 | now, |
| 337 | now, |
| 338 | ), |
| 339 | ) |
| 340 | conn.commit() |
| 341 | row = cursor.execute( |
| 342 | "SELECT * FROM wiki_nodes WHERE user_id = ? AND node_id = ?", |
| 343 | (user_id, node_id), |
| 344 | ).fetchone() |
| 345 | conn.close() |
nothing calls this directly
no test coverage detected