Node.js

Node.js client for ChronDB, built with NAPI-RSarrow-up-right from the Rust SDK.

Requirements

  • Node.js 16+

Installation

npm install chrondb

Quick Start

const { ChronDB } = require('chrondb')

// Single path (preferred)
const db = new ChronDB('./mydb')

// Save a document
db.put('user:1', { name: 'Alice', age: 30 })

// Retrieve it
const doc = db.get('user:1')
console.log(doc) // { name: 'Alice', age: 30 }

Legacy API (deprecated): new ChronDB('/tmp/data', '/tmp/index') still works but is deprecated. Use the single-path form instead.

ES Modules

API Reference

new ChronDB(dbPath, options?)

Opens a database connection using a single directory path.

Parameter
Type
Description

dbPath

string

Path for the database (data and index stored inside)

options.idleTimeout

number

Seconds of inactivity before suspending the GraalVM isolate

Throws: Error if the database cannot be opened.

Legacy: new ChronDB(dataPath, indexPath, options?)

Deprecated. The two-path constructor still works but is deprecated. Use the single-path form above.

Parameter
Type
Description

dataPath

string

Path for the Git repository (data storage)

indexPath

string

Path for the Lucene index

options.idleTimeout

number

Seconds of inactivity before suspending the GraalVM isolate


put(id, doc, branch?) -> Object

Saves a document.

Parameter
Type
Description

id

string

Document ID (e.g., "user:1")

doc

Object

Document data

branch

string | null

Branch name


get(id, branch?) -> Object

Retrieves a document by ID.

Throws: Error if not found.


delete(id, branch?) -> void

Deletes a document by ID.


listByPrefix(prefix, branch?) -> Object[]

Lists documents whose IDs start with the given prefix.


listByTable(table, branch?) -> Object[]

Lists all documents in a table.


history(id, branch?) -> Object[]

Returns the change history of a document.


query(query, branch?) -> Object

Executes a query against the Lucene index.


execute(sql, branch?) -> Object

Executes a SQL query directly against the database without needing a running server.

Parameter
Type
Description

sql

string

SQL query string

branch

string | null

Branch name

Returns: Result object with type, columns, rows, count.

TypeScript

Full TypeScript definitions are included:

Error Handling

Examples

Full CRUD

Idle Timeout (long-running services)

SQL Queries

Execute SQL queries directly without needing a running server:

Query

History (Time Travel)

Last updated

Was this helpful?