This document provides detailed information about the ChronDB API.
(require '[chrondb.core :as chrondb])
;; Create with default configuration
(def db (chrondb/create-chrondb))
;; Create with custom configuration
(def db (chrondb/create-chrondb config))
(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
(chrondb/get db "key")
Parameters:
db
: ChronDB instancekey
: String identifier for the document
Returns: The document if found, nil otherwise
(chrondb/delete db "key")
Parameters:
db
: ChronDB instancekey
: String identifier for the document
Returns: true if document was deleted, false otherwise
(chrondb/search db query)
(chrondb/search db query {:limit 10 :offset 0})
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
(chrondb/history db "key")
Parameters:
db
: ChronDB instancekey
: String identifier for the document
Returns: Sequence of document versions with timestamps
(chrondb/get-at db "key" timestamp)
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
(chrondb/diff db "key" timestamp1 timestamp2)
Parameters:
db
: ChronDB instancekey
: String identifier for the documenttimestamp1
: First timestamptimestamp2
: Second timestamp
Returns: Differences between versions
(chrondb/create-branch db "branch-name")
Parameters:
db
: ChronDB instancebranch-name
: Name of the new branch
Returns: Updated ChronDB instance
(chrondb/switch-branch db "branch-name")
Parameters:
db
: ChronDB instancebranch-name
: Name of the branch to switch to
Returns: Updated ChronDB instance
(chrondb/merge-branch db "source-branch" "target-branch")
Parameters:
db
: ChronDB instancesource-branch
: Branch to merge fromtarget-branch
: Branch to merge into
Returns: Updated ChronDB instance
(chrondb/with-transaction [db]
(chrondb/save db "key1" value1)
(chrondb/save db "key2" value2))
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
(chrondb/register-hook db :pre-save
(fn [doc]
;; Hook logic here
doc))
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
(chrondb/health-check db)
Returns: Map with health status information
(chrondb/backup db "backup-path")
Creates a complete backup of the database
(chrondb/stats db)
Returns: Map with database statistics
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:
(try
(chrondb/save db "key" value)
(catch chrondb.exceptions.StorageException e
(log/error "Storage error:" (.getMessage e)))
(catch chrondb.exceptions.ValidationException e
(log/error "Validation error:" (.getMessage e))))