{"id":16639,"library":"levelgraph","title":"LevelGraph - Graph Database","description":"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.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/levelgraph/levelgraph","tags":["javascript","leveldb","graph","level","database","triples","triple"],"install":[{"cmd":"npm install levelgraph","lang":"bash","label":"npm"},{"cmd":"yarn add levelgraph","lang":"bash","label":"yarn"},{"cmd":"pnpm add levelgraph","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"The core underlying key-value store wrapper, essential for all database operations. LevelGraph v4.0.0 specifically requires `level` v8.","package":"level","optional":false},{"reason":"Added in v3.0.0, likely used for temporary file operations related to testing or internal database management.","package":"tmp","optional":true}],"imports":[{"note":"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.","wrong":"import levelgraph from 'levelgraph';","symbol":"levelgraph","correct":"const levelgraph = require('levelgraph');"},{"note":"The underlying `level` dependency itself supports both CommonJS and ESM. LevelGraph's examples currently show CommonJS `require` for `Level` as well.","wrong":"import { Level } from 'level';","symbol":"Level","correct":"const { Level } = require('level');"},{"note":"Triples must be provided as an object with `subject`, `predicate`, and `object` properties.","wrong":"db.put('s', 'p', 'o', callback);","symbol":"db.put","correct":"db.put({ subject: 's', predicate: 'p', object: 'o' }, callback);"}],"quickstart":{"code":"const { Level } = require('level');\nconst levelgraph = require('levelgraph');\nconst path = require('path');\nconst os = require('os');\nconst fs = require('fs');\n\n// Create a temporary directory for the database\nconst dbPath = path.join(os.tmpdir(), `levelgraph-test-${Date.now()}`);\n\n// Initialize the database with a LevelDB store\nconst db = levelgraph(new Level(dbPath));\n\nconst triple = { subject: 'book', predicate: 'hasAuthor', object: 'Alice' };\n\ndb.put(triple, function(err) {\n  if (err) {\n    console.error('Error putting triple:', err);\n    return;\n  }\n  console.log('Triple inserted:', triple);\n\n  // Retrieve triples matching a pattern\n  db.get({ subject: 'book', predicate: 'hasAuthor' }, function(err, triples) {\n    if (err) {\n      console.error('Error getting triples:', err);\n      return;\n    }\n    console.log('Retrieved triples:', triples);\n    // Expected output: [{ subject: 'book', predicate: 'hasAuthor', object: 'Alice' }]\n\n    // Clean up: close the database and remove the directory\n    db.close(function(closeErr) {\n      if (closeErr) console.error('Error closing db:', closeErr);\n      else console.log('Database closed.');\n      fs.rm(dbPath, { recursive: true, force: true }, (rmErr) => {\n        if (rmErr) console.error('Error removing database directory:', rmErr);\n        else console.log('Database directory removed.');\n      });\n    });\n  });\n});","lang":"javascript","description":"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."},"warnings":[{"fix":"Review the changelog for `level` v8 for specific breaking changes. Update your `level` related code if directly interacting with the `level` API used by LevelGraph. Test thoroughly after upgrading.","message":"LevelGraph v4.0.0 updates its internal `level` dependency to v8. This update can introduce breaking changes from the `level` library itself, particularly regarding its asynchronous API and potential Node.js version requirements. Ensure compatibility with your existing `level` usage.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Upgrade to LevelGraph v3.0.0 or later to leverage the `level` package which offers better compatibility and browser support. If you were explicitly using `level-browserify` in your build, switch to `level`.","message":"In v3.0.0, `level-browserify` was replaced by `level` as the underlying store for browser environments. `level-browserify` was noted to have installation issues on newer Node.js versions, making this a critical upgrade for compatibility.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"If your application code directly interacts with streams returned by LevelGraph and relies on `close` or `end` events, review your stream handling logic for potential subtle behavioral changes after upgrading to v3.0.0.","message":"Stream closing behavior for internal tests in v3.0.0 was changed from listening to the `close` event to the `end` event due to double-triggering. While this primarily affected internal tests, developers relying on specific stream lifecycle events in their own code might experience different behavior.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"For production deployments, target Node.js 18 or 20. If using other versions, ensure comprehensive testing of your application's LevelGraph interactions.","message":"LevelGraph officially tests only against Node.js versions 18 and 20. While other versions may function, their support is not guaranteed, and compatibility issues might arise.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Upgrade `levelgraph` to version 3.0.0 or higher. This version replaces `level-browserify` with the more compatible `level` package.","cause":"This error typically occurs when using LevelGraph versions prior to 3.0.0 with newer Node.js environments, where the deprecated `level-browserify` package had installation issues.","error":"Error: Cannot find module 'level-browserify'"},{"fix":"Ensure that all arguments expected to be objects (like triple patterns for `db.get` or `db.put`) are indeed valid JavaScript objects. If you are on an older version, upgrade to `levelgraph` v1.1.3 or newer.","cause":"Reported in older versions (fixed in v1.1.3), this error indicates that a non-object value was passed where an object (e.g., a triple pattern) was expected, causing `Object.keys()` to fail.","error":"TypeError: Object.keys called on non-object"},{"fix":"Always provide a valid, non-empty string path when initializing `new Level('your-database-path')`. Ensure your database path variable is correctly defined and not `null` or `undefined`.","cause":"This is a common error from the underlying `level` library when its constructor `new Level()` is called without a valid string path for the database directory.","error":"Error: The 'path' argument must be of type string. Received undefined"}],"ecosystem":"npm"}