LevelGraph is a graph database implemented for both Node.js and browser environments, leveraging the high-performance LevelDB key-value store through the `level` library. Currently stable at version 4.0.0, its release cadence appears to be tied to significant updates in its underlying `level` dependency, as seen with the v4.0.0 release updating to `level` v8. A key differentiator is its implementation of the Hexastore approach, employing six indices for each triple (subject, predicate, object) to ensure rapid data access and pattern matching. It supports standard graph database operations like triple insertion, retrieval, and deletion, with capabilities for advanced searches and filtering. It offers a consistent API across Node.js and browser contexts, though initialization differs slightly.
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
LevelGraph's primary entry point is a CommonJS module exporting a factory function. While Node.js supports ESM, the package itself is not a pure ESM module. For modern ESM environments, consider using a CommonJS compatibility wrapper or a bundler.
const levelgraph = require('levelgraph');
The underlying `level` dependency itself supports both CommonJS and ESM. LevelGraph's examples currently show CommonJS `require` for `Level` as well.
const { Level } = require('level');
Triples must be provided as an object with `subject`, `predicate`, and `object` properties.
db.put({ subject: 's', predicate: 'p', object: 'o' }, callback);
This quickstart demonstrates how to initialize a LevelGraph database, insert a triple, retrieve it using a pattern match, and then properly clean up the database resources.
const { Level } = require('level');
const levelgraph = require('levelgraph');
const path = require('path');
const os = require('os');
const fs = require('fs');
// Create a temporary directory for the database
const dbPath = path.join(os.tmpdir(), `levelgraph-test-${Date.now()}`);
// Initialize the database with a LevelDB store
const db = levelgraph(new Level(dbPath));
const triple = { subject: 'book', predicate: 'hasAuthor', object: 'Alice' };
db.put(triple, function(err) {
if (err) {
console.error('Error putting triple:', err);
return;
}
console.log('Triple inserted:', triple);
// Retrieve triples matching a pattern
db.get({ subject: 'book', predicate: 'hasAuthor' }, function(err, triples) {
if (err) {
console.error('Error getting triples:', err);
return;
}
console.log('Retrieved triples:', triples);
// Expected output: [{ subject: 'book', predicate: 'hasAuthor', object: 'Alice' }]
// Clean up: close the database and remove the directory
db.close(function(closeErr) {
if (closeErr) console.error('Error closing db:', closeErr);
else console.log('Database closed.');
fs.rm(dbPath, { recursive: true, force: true }, (rmErr) => {
if (rmErr) console.error('Error removing database directory:', rmErr);
else console.log('Database directory removed.');
});
});
});
});
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.