Cozo-node is a Node.js binding for CozoDB, an embedded Datalog and graph database. It provides direct native access to CozoDB's capabilities, allowing developers to embed a powerful, relational-like database engine directly within their Node.js applications. The current stable version is 0.7.6, with recent minor releases indicating active development. Cozo-node differentiates itself by offering various storage engines, including in-memory ('mem'), SQLite, and RocksDB (depending on compile-time flags), enabling flexible persistence options. It exposes a simple API for running Datalog queries, managing relations, and handling database backups and restores. While primarily accessed via JavaScript/TypeScript, its underlying implementation is in Rust, providing high performance and low-level control. This library is suitable for applications requiring an embedded, queryable knowledge base or a lightweight graph database solution.
npm install cozo-nodeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize an in-memory CozoDb instance, perform basic data insertion, query data with and without parameters, and execute more complex Datalog queries with relations, ensuring proper database closure.
Always ensure `db.close()` is called for every `CozoDb` instance when it's no longer needed, typically within a `finally` block or a resource cleanup hook.
If `npm install` fails with a binary-related error, you may need to compile the package from source. This requires a Rust toolchain. Refer to the 'Building' section in the package's README for detailed instructions.
If trigger activation is essential for imported data, use regular Datalog queries with parameters for data insertion, as these will correctly activate any associated triggers.
Ensure the `CozoDb` instance is newly created or completely empty before attempting a `restore` operation. For existing databases, consider using `importRelationsFromBackup` if specific relations need to be merged.
Install a Rust toolchain (`rustup.rs`) and then try installing the package with `npm install --build-from-source cozo-node` or by following the manual build steps in the README.
For ES Modules, use `import { CozoDb } from 'cozo-node';`. For CommonJS, use destructuring: `const { CozoDb } = require('cozo-node');`.Examine the `err.display` or `err.message` property for specific CozoDB error details. Review your Datalog script and parameters for syntax, relation existence, and data consistency.
No dependency data recorded yet.