Clojure API

This document provides detailed information about the ChronDB API.

Core API (Clojure/Java)

Creating a Database

(require '[chrondb.core :as chrondb])

;; Create with default configuration
(def db (chrondb/create-chrondb))

;; Create with custom configuration
(def db (chrondb/create-chrondb config))

Document Operations

Save Document

(chrondb/save db "key" value)

Parameters:

  • db: ChronDB instance

  • key: String identifier for the document

  • value: Document data (will be stored as JSON)

Returns: The saved document

Get Document

Parameters:

  • db: ChronDB instance

  • key: String identifier for the document

Returns: The document if found, nil otherwise

Delete Document

Parameters:

  • db: ChronDB instance

  • key: String identifier for the document

Returns: true if document was deleted, false otherwise

Search Operations

Search Documents

Parameters:

  • db: ChronDB instance

  • query: Lucene query string

  • options: Optional map with:

    • :limit: Maximum number of results (default: 10)

    • :offset: Number of results to skip (default: 0)

Returns: Sequence of matching documents

Version Control Operations

Get Document History

Parameters:

  • db: ChronDB instance

  • key: String identifier for the document

Returns: Sequence of document versions with timestamps

Get Document at Point in Time

Parameters:

  • db: ChronDB instance

  • key: String identifier for the document

  • timestamp: ISO-8601 timestamp string or java.time.Instant

Returns: The document as it existed at the specified time

Compare Document Versions

Parameters:

  • db: ChronDB instance

  • key: String identifier for the document

  • timestamp1: First timestamp

  • timestamp2: Second timestamp

Returns: Differences between versions

Branch Operations

Create Branch

Parameters:

  • db: ChronDB instance

  • branch-name: Name of the new branch

Returns: Updated ChronDB instance

Switch Branch

Parameters:

  • db: ChronDB instance

  • branch-name: Name of the branch to switch to

Returns: Updated ChronDB instance

Merge Branches

Parameters:

  • db: ChronDB instance

  • source-branch: Branch to merge from

  • target-branch: Branch to merge into

Returns: Updated ChronDB instance

Transaction Operations

All operations within the transaction block are atomic:

  • Either all succeed or all fail

  • Changes are only visible after successful commit

  • Automatic rollback on failure

Transaction Metadata and Git Notes

ChronDB attaches a structured Git note to every commit. The payload includes the transaction id (tx_id), origin, optional user identifier, flags, and request metadata. You can enrich this payload by providing HTTP headers on REST requests:

Header
Description

X-ChronDB-Origin

Overrides the origin label stored in the note (defaults to rest).

X-ChronDB-User

Associates commits with an authenticated user id or service account.

X-ChronDB-Flags

Comma-separated list of semantic flags (for example: bulk-load, migration).

X-Request-Id / X-Correlation-Id

Propagate request correlation identifiers into commit metadata.

All ChronDB front-ends (REST, Redis, SQL) reuse the same transaction core, so commits that belong to the same logical operation share the same tx_id. Special operations automatically set semantic flags. For instance, document imports mark the transaction with bulk-load, and restore flows add rollback.

Inspect commit notes with standard Git tooling:

You can parse the JSON payload to correlate commits with external systems or audit trails.

Event Hooks

Register Hook

Available hook points:

  • :pre-save: Before saving a document

  • :post-save: After saving a document

  • :pre-delete: Before deleting a document

  • :post-delete: After deleting a document

Utility Functions

Health Check

Returns: Map with health status information

Backup / Restore

Scheduled backup example:

Statistics

Returns: Map with database statistics

Error Handling

All API functions may throw the following exceptions:

  • ChronDBException: Base exception class

  • StorageException: Storage-related errors

  • IndexException: Index-related errors

  • ConfigurationException: Configuration errors

  • ValidationException: Data validation errors

Example error handling:

Last updated