import json import os from typing import List, Dict, Any class SimpleNoSQL: def __init__(self, db_path: str= "db.json"): self.db_path = db_path if os.path.exists(self.db_path): with open(self.db_path, "r") as f: self.data = json.load(f) else: self.data = [] def save(self): with open(self.db_path, "w") as f: json.dump(self.data, f, indent=2) def insert(self, document: Dict[str, Any]): self.data.append(document) self.save() def find(self, query: Dict[str, Any]) -> List[Dict[str, Any]]: def match(doc): return all(doc.get(k) == v for k, v in query.items()) return [doc for doc in self.data if match(doc)] def update(self, query: Dict [str, Any], update_fields: Dict[str, Any]): for doc in self.data: if all(doc.get(k) == v for k, v in query.items()): doc.update(update_fields) self.save() def delete(self, query: Dict[str, Any]): self.data = [doc for doc in self.data if not all(doc.get(k) == v for k, v in query.items())] self.save db = SimpleNoSQL() db.insert({ "session_id": "abc123", "code": "fn main() { println!(\"Hello\"); }", "output": "Hello", "status": "success" }) results = db.find({"session_id": "abc123"}) print("検索結果:", results) db.update({"session_id": "abc123"}, {"status": "reviewed"})
[
{
“session_id”: “abc123”,
“code”: “fn main() { println!(\”Hello\”); }”,
“output”: “Hello”,
“status”: “reviewed”
}
]
これをRustでやりたい