Ruby

Ruby client for ChronDB, auto-generated from the Rust SDK via UniFFIarrow-up-right.

Requirements

  • Ruby 3.0+

Installation

gem install chrondb

Quick Start

require "chrondb"

# Single path (preferred)
db = ChronDB::Client.new("./mydb")

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

# Retrieve it
doc = db.get("user:1")
puts doc  # {"name"=>"Alice", "age"=>30}

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

API Reference

ChronDB::Client.new(db_path, idle_timeout: nil)

Opens a database connection using a single directory path.

Parameter
Type
Description

db_path

String

Path for the database (data and index stored inside)

idle_timeout

Integer

Seconds of inactivity before suspending the GraalVM isolate

Raises: ChronDB::Error if the database cannot be opened.

Legacy: ChronDB::Client.new(data_path, index_path, idle_timeout: nil)

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

Parameter
Type
Description

data_path

String

Path for the Git repository (data storage)

index_path

String

Path for the Lucene index

idle_timeout

Integer

Seconds of inactivity before suspending the GraalVM isolate


put(id, doc, branch: nil) -> Hash

Saves a document.

Parameter
Type
Description

id

String

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

doc

Hash

Document data

branch

String

Branch name (nil for default)


get(id, branch: nil) -> Hash

Retrieves a document by ID.

Raises: ChronDB::DocumentNotFoundError if not found.


delete(id, branch: nil) -> true

Deletes a document by ID.

Raises: ChronDB::DocumentNotFoundError if not found.


list_by_prefix(prefix, branch: nil) -> Array<Hash>

Lists documents whose IDs start with the given prefix.


list_by_table(table, branch: nil) -> Array<Hash>

Lists all documents in a table.


history(id, branch: nil) -> Array<Hash>

Returns the change history of a document.


query(query, branch: nil) -> Hash

Executes a query against the Lucene index.


execute(sql, branch: nil) -> Hash

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

Parameter
Type
Description

sql

String

SQL query string

branch

String

Branch name (nil for default)

Returns: Hash with keys type, columns, rows, count.

Raises: ChronDB::Error on failure.

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?