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 instancekey: String identifier for the documentvalue: Document data (will be stored as JSON)
Returns: The saved document
Get Document
Parameters:
db: ChronDB instancekey: String identifier for the document
Returns: The document if found, nil otherwise
Delete Document
Parameters:
db: ChronDB instancekey: String identifier for the document
Returns: true if document was deleted, false otherwise
Search Operations
Search Documents
Parameters:
db: ChronDB instancequery: Lucene query stringoptions: 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 instancekey: String identifier for the document
Returns: Sequence of document versions with timestamps
Get Document at Point in Time
Parameters:
db: ChronDB instancekey: String identifier for the documenttimestamp: ISO-8601 timestamp string or java.time.Instant
Returns: The document as it existed at the specified time
Compare Document Versions
Parameters:
db: ChronDB instancekey: String identifier for the documenttimestamp1: First timestamptimestamp2: Second timestamp
Returns: Differences between versions
Branch Operations
Create Branch
Parameters:
db: ChronDB instancebranch-name: Name of the new branch
Returns: Updated ChronDB instance
Switch Branch
Parameters:
db: ChronDB instancebranch-name: Name of the branch to switch to
Returns: Updated ChronDB instance
Merge Branches
Parameters:
db: ChronDB instancesource-branch: Branch to merge fromtarget-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:
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 classStorageException: Storage-related errorsIndexException: Index-related errorsConfigurationException: Configuration errorsValidationException: Data validation errors
Example error handling:
Last updated
Was this helpful?