zyxdb
v0.1.15
Published
Node.js bindings for ZYX graph database
Maintainers
Readme
zyxdb
Node.js bindings for ZYX, a high-performance embeddable graph database engine with Cypher query support.
Installation
npm install zyxdbPrebuilt native binaries are available for:
| Platform | Architecture | |----------|-------------| | Linux | x64 (glibc) | | macOS | ARM64 (Apple Silicon) | | Windows | x64 (MSVC) |
Build from source
cd bindings/nodejs
npm installRequires CMake, a C++20 compiler, and Conan 2 for dependencies.
Quick Start
const { Database } = require('zyxdb');
async function main() {
const db = new Database('/tmp/movies');
await db.open();
// Create nodes — returns node ID (number)
const alice = await db.createNode('Person', { name: 'Alice', age: 30 });
const bob = await db.createNode('Person', { name: 'Bob', age: 25 });
const carol = await db.createNode('Person', { name: 'Carol', age: 35 });
// Create edges between nodes
await db.createEdge(alice, bob, 'FRIENDS_WITH');
await db.createEdge(bob, carol, 'FRIENDS_WITH');
// Cypher works too — with parameterized queries
await db.execute(
'CREATE (m:Movie {title: $title, year: $year})',
{ title: 'The Matrix', year: 1999 }
);
// Transactions — all or nothing
const tx = await db.beginTransaction();
await tx.execute(
"MATCH (p:Person {name: 'Alice'}), (m:Movie {title: 'The Matrix'}) " +
"CREATE (p)-[:RATED {score: 9.5}]->(m)"
);
await tx.execute(
"MATCH (p:Person {name: 'Bob'}), (m:Movie {title: 'The Matrix'}) " +
"CREATE (p)-[:RATED {score: 10.0}]->(m)"
);
await tx.commit();
// Query with iteration
const result = await db.execute(
'MATCH (p:Person)-[r:RATED]->(m:Movie) ' +
'RETURN p.name AS person, m.title AS movie, r.score AS score'
);
for (const row of result) {
console.log(`${row.person} rated ${row.movie} ${row.score}/10`);
}
// Read-only transaction for safe reads
const roTx = await db.beginReadOnlyTransaction();
const counts = await roTx.execute('MATCH (p:Person) RETURN count(p) AS cnt');
console.log(`Total people: ${counts.scalar()}`);
await roTx.commit();
// Shortest path
const path = await db.getShortestPath(alice, carol);
const names = path.map(n => n.properties.name);
console.log(names.join(' -> ')); // Alice -> Bob -> Carol
await db.close();
}
main();Supported Value Types
| JavaScript | ZYX |
|------------|-----|
| null | null |
| boolean | bool |
| number (integer) | int64 |
| number (float) | double |
| string | string |
| number[] | vector (embeddings) |
| string[] | string list |
| Array (mixed) | heterogeneous list |
| Object | map |
API Reference
Database(dbPath)
open()— Open the database (creates if not exists)close()— Close the databasesave()— Flush data to diskexecute(cypher, params?)— Execute Cypher query with optional parametersbeginTransaction()— Start a read-write transactionbeginReadOnlyTransaction()— Start a read-only transactioncreateNode(label, props?)— Create a node, return its ID (labelcan bestringorstring[])createNodes(label, propsList)— Batch create nodes, return array of IDscreateEdge(srcId, dstId, edgeType, props?)— Create edge between two nodes by IDcreateEdges(edgeType, edges)— Batch create edgesgetShortestPath(startId, endId, maxDepth?)— Find shortest path, return array ofNodehasActiveTransaction— Whether there is an active transaction
All methods return Promise — use await or .then().
Transaction
execute(cypher, params?)— Execute within transactioncommit()— Commit changesrollback()— Roll back changesisActive— Whether transaction is still activeisReadOnly— Whether read-only
Result
- Iterable:
for (const row of result)yieldsRecordobjects columns— Array of column namesisSuccess— Whether query succeedederror— Error message ornullduration— Query execution time (ms)records— All records as arrayfetchAll()— Fetch all recordssingle(strict?)— Return the single result recordscalar()— Return first column of first rowdata()— Return all rows as array of plain objects
Record
get(key)— Get value by column name or indexkeys()— Array of column namesvalues()— Array of valuesdata()— Plain object of key-value pairslength— Number of columns- Property access:
row.nameis equivalent torow.get('name')
TypeScript Support
Full TypeScript definitions are included:
import { Database, Result, Record, Transaction } from 'zyxdb';License
Apache License 2.0
