Skip to content
~/docs/api/low-level
DOCUMENTATION

Low-Level API

Direct database primitives

The low-level API uses the Database class for direct graph operations, transaction control, and batched writes.

Open and Write

typescript
import { Database, PropType } from '@kitedb/core';

const db = Database.open('./data.kitedb', { createIfMissing: true });

db.begin();
try {
  const nodeId = db.createNode('user:alice');
  db.setNodePropByName(nodeId, 'name', {
    propType: PropType.String,
    stringValue: 'Alice',
  });

  db.commit();
} catch (err) {
  db.rollback();
  throw err;
}

Batch Operations

typescript
// High-throughput bulk ingest
db.beginBulk();
const nodeIds = db.createNodesBatch(keys); // Array<string | null>
db.addEdgesBatch(edges);                   // Array<{ src, etype, dst }>
db.addEdgesWithPropsBatch(edgesWithProps);
db.commit();

// Optional maintenance checkpoint after ingest
db.checkpoint();

Streaming and Pagination

typescript
// Stream nodes in fixed-size chunks
for (const batch of db.streamNodes({ batchSize: 1000 })) {
  for (const nodeId of batch) {
    // process nodeId
  }
}

// Cursor pagination
let cursor: string | undefined = undefined;
do {
  const page = db.getNodesPage({ limit: 100, cursor });
  for (const node of page.items) {
    // process node
  }
  cursor = page.nextCursor;
} while (cursor);