Queries de escritura
El lado de escritura de NamiDB es Cypher-native. Cada llamada de escritura dentro de los clientes de Python / Rust / HTTP hace commit al retornar — el WAL append + el manifest CAS ocurren de forma sincrónica.
CREATE
CREATE (a:Person {name: 'Alice', age: 30})Asigna un NodeId interno nuevo. Para controlar el NodeId
explícitamente, pasar _id:
CREATE (a:Person {_id: $uuid, name: 'Alice'})Edges
MATCH (a:Person {_id: $a}), (b:Person {_id: $b})CREATE (a)-[r:KNOWS {since: 2020}]->(b)El pattern requiere que ambos endpoints estén bound; NamiDB no
auto-crea endpoints en un CREATE de edge.
MERGE
MERGE es la primitiva de upsert — matchea si existe, crea si no.
MERGE (p:Person {_id: $uuid})ON CREATE SET p.created_at = datetime()ON MATCH SET p.last_seen = datetime()MATCH (a:Person {_id: $a}), (b:Person {_id: $b})MERGE (a)-[r:KNOWS]->(b)ON CREATE SET r.since = datetime()SET
MATCH (p:Person {_id: $id})SET p.age = $age, p.last_seen = datetime()Actualización bulk vía map:
MATCH (p:Person {_id: $id})SET p += {age: $age, country: $country, last_seen: datetime()}DELETE / DETACH DELETE
MATCH (p:Person {_id: $id}) DELETE p // da error si p tiene edgesMATCH (p:Person {_id: $id}) DETACH DELETE p // borra p + sus edgesREMOVE
MATCH (p:Person {_id: $id}) REMOVE p.old_fieldMATCH (n:Person) REMOVE n:Pending // remueve una labelCombinar escrituras con lecturas
MATCH (a:Person {_id: $a})WITH aMATCH (b:Person {_id: $b})CREATE (a)-[r:KNOWS {since: 2020}]->(b)RETURN rInserts bulk (Python)
Para ingesta de alto volumen, conviene usar las APIs de staging bulk en
vez de un CREATE por fila:
import uuidimport namidb as tg
client = tg.Client("s3://my-bucket?ns=prod®ion=us-east-1")
client.merge_nodes( "Person", [{"id": str(uuid.uuid4()), "name": f"p{i}", "age": 20 + i} for i in range(10_000)],)client.merge_edges( "KNOWS", [{"src": "uuid-a", "dst": "uuid-b", "since": 2020}],)client.commit() # WAL + manifest CASclient.flush() # memtable -> L0 SSTsEstas APIs hacen staging en el batch actual (mismo lifecycle que
upsert_*) y amortizan un único round-trip de tokio-runtime + mutex
sobre miles de filas.