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 | keywords = str(node.get("keywords") or "").strip() |
| 287 | if keywords: |
| 288 | lines.extend([f"Keywords: {keywords}", ""]) |
| 289 | if metadata: |
| 290 | lines.extend(["## Metadata", "", "```json", json.dumps(metadata, ensure_ascii=False, indent=2), "```", ""]) |
| 291 | lines.extend(["## Body", "", str(node.get("body") or "").strip(), ""]) |
| 292 | output_path.write_text("\n".join(lines), encoding="utf-8") |
| 293 | return relative_path |
| 294 | |
| 295 | |
| 296 | def upsert_node( |
| 297 | *, |
| 298 | user_id: str, |
| 299 | node_id: str, |
| 300 | node_type: str, |
| 301 | title: str, |
| 302 | body: str, |
| 303 | metadata: Optional[Dict[str, Any]] = None, |
| 304 | keywords: Optional[str] = None, |
| 305 | source_type: Optional[str] = None, |
| 306 | source_ref: Optional[str] = None, |
| 307 | file_path: Optional[str] = None, |
| 308 | write_mirror: bool = True, |
| 309 | ) -> Dict[str, Any]: |
| 310 | """Insert or update a wiki node and optionally refresh its Markdown mirror.""" |
| 311 | init_wiki_schema() |
| 312 | now = _now() |
| 313 | relative_path = file_path or _relative_file_path(user_id, node_type, node_id) |
| 314 | conn = db_ops.get_connection() |
| 315 | cursor = conn.cursor() |
| 316 | cursor.execute( |
| 317 | """ |
| 318 | INSERT INTO wiki_nodes |
| 319 | (node_id, user_id, node_type, title, body, metadata_json, |
| 320 | keywords, file_path, source_type, source_ref, created_at, updated_at) |
| 321 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
| 322 | ON CONFLICT(user_id, node_id) DO UPDATE SET |
| 323 | node_type=excluded.node_type, |
| 324 | title=excluded.title, |
| 325 | body=excluded.body, |
| 326 | metadata_json=excluded.metadata_json, |
| 327 | keywords=excluded.keywords, |
| 328 | file_path=excluded.file_path, |
| 329 | source_type=excluded.source_type, |
| 330 | source_ref=excluded.source_ref, |
| 331 | updated_at=excluded.updated_at |
| 332 | """, |
| 333 | ( |
| 334 | node_id, |
| 335 | user_id, |
| 336 | node_type, |
| 337 | title or node_id, |
| 338 | body or "", |
| 339 | _json_dumps(metadata), |
| 340 | keywords or "", |
| 341 | relative_path, |
| 342 | source_type, |
| 343 | source_ref, |
| 344 | now, |
| 345 | now, |
nothing calls this directly
no test coverage detected