Package Exports
- @grafeo-db/js
- @grafeo-db/js/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@grafeo-db/js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@grafeo-db/js
Node.js/TypeScript bindings for Grafeo, a high-performance, embeddable graph database with a Rust core.
Installation
npm install @grafeo-db/jsQuick Start
import { GrafeoDB } from '@grafeo-db/js';
// In-memory database
const db = GrafeoDB.create();
// Or persistent
// const db = GrafeoDB.create('./my-graph');
// Create nodes
db.createNode(['Person'], { name: 'Alix', age: 30 });
db.createNode(['Person'], { name: 'Gus', age: 25 });
db.createEdge(0, 1, 'KNOWS', { since: 2024 });
// Query with GQL
const result = await db.execute('MATCH (p:Person) WHERE p.age > 20 RETURN p.name, p.age');
for (const row of result.toArray()) {
console.log(row);
}
db.close();API Reference
Database
// Create / open
const db = GrafeoDB.create(); // in-memory
const db = GrafeoDB.create('./path'); // persistent
const db = GrafeoDB.open('./path'); // open existing
// Counts
db.nodeCount(); // number of nodes
db.edgeCount(); // number of edgesQuery Languages
All query methods return Promise<QueryResult> and accept optional parameters:
await db.execute(gql, params?); // GQL (ISO standard)
await db.executeCypher(query, params?); // Cypher
await db.executeGremlin(query, params?); // Gremlin
await db.executeGraphql(query, params?); // GraphQL
await db.executeSparql(query); // SPARQLNode & Edge CRUD
const node = db.createNode(['Label'], { key: 'value' });
const edge = db.createEdge(sourceId, targetId, 'TYPE', { key: 'value' });
const n = db.getNode(id); // JsNode | null
const e = db.getEdge(id); // JsEdge | null
db.setNodeProperty(id, 'key', 'value');
db.setEdgeProperty(id, 'key', 'value');
db.deleteNode(id); // returns boolean
db.deleteEdge(id); // returns booleanTransactions
const tx = db.beginTransaction();
try {
await tx.execute("INSERT (:Person {name: 'Harm'})");
tx.commit();
} catch (e) {
tx.rollback();
}
// Node.js 22+ with explicit resource management:
using tx = db.beginTransaction();
await tx.execute("INSERT (:Person {name: 'Harm'})");
tx.commit(); // auto-rollback if not committedQueryResult
result.columns; // column names
result.length; // row count
result.executionTimeMs; // execution time (ms)
result.get(0); // single row as object
result.toArray(); // all rows as objects
result.scalar(); // first column of first row
result.nodes(); // extracted nodes
result.edges(); // extracted edgesGraph Projections
await db.createProjection('people', {
nodeLabels: ['Person'],
edgeTypes: ['KNOWS']
});
const projections = db.listProjections(); // ['people']
db.dropProjection('people');Data Import
const count = await db.importCsv('./users.csv', { label: 'Person', headers: true });
const count2 = await db.importJsonl('./events.jsonl', 'Event');Backup and Restore
await db.backupFull('/backups/full');
await db.backupIncremental('/backups/incr');
await GrafeoDB.restoreToEpoch('/backups/full', 100, './restored');Vector Search
// Create an HNSW index
await db.createVectorIndex('Document', 'embedding', 384);
// Bulk insert
const ids = await db.batchCreateNodes('Document', 'embedding', vectors);
// Search
const results = await db.vectorSearch('Document', 'embedding', queryVector, 10);Features
- GQL, Cypher, SPARQL, Gremlin and GraphQL query languages
- Full node/edge CRUD with property management
- ACID transactions with automatic rollback
- HNSW vector similarity search with batch operations
- Graph projections (filtered virtual views)
- CSV and JSON Lines import
- Incremental backup and restore
- Async/await API backed by Rust + Tokio
- TypeScript definitions included
Links
License
Apache-2.0