The native Clojure API offers the most direct way to interact with ChronDB, providing access to all features including CRUD operations, searching, version control, and branching.
;; Basic example(require '[chrondb.core :as chrondb])(def db (chrondb/create-chrondb))(chrondb/save db "user:1"{:name "Alice" :email "[email protected]"})
The REST API allows you to interact with ChronDB using HTTP requests, making it easy to integrate with any programming language or environment that can make HTTP requests.
# Create a document using curlcurl-XPOSThttp://localhost:3000/api/v1/documents/user:1\-H"Content-Type: application/json"\-d'{"name": "John Doe", "email": "[email protected]"}'
# Using redis-cli
redis-cli -h localhost -p 6379
> SET user:1 '{"name":"John Doe","email":"[email protected]"}'
-- Create a document using psql
INSERT INTO user (id, name, email)
VALUES ('1', 'John Doe', '[email protected]');
-- View all changes to a user document
SELECT * FROM chrondb_history('user', '1');
-- Extract only specific history information
SELECT commit_id, timestamp FROM chrondb_history('user', '1');
-- Find the most recent 5 changes
SELECT * FROM chrondb_history('user', '1') LIMIT 5;
-- View document as it was at a specific commit
SELECT * FROM chrondb_at('user', '1', 'abc123def456');
-- Extract specific fields from a historical version
SELECT name, email FROM chrondb_at('user', '1', 'abc123def456');
-- Compare with current version
SELECT
current.name AS current_name,
history.name AS previous_name
FROM
user AS current,
chrondb_at('user', '1', 'abc123def456') AS history
WHERE
current.id = '1';
-- Compare two versions of a document
SELECT * FROM chrondb_diff('user', '1', 'abc123def456', 'def456abc123');
-- Check only what fields changed
SELECT changed FROM chrondb_diff('user', '1', 'abc123def456', 'def456abc123');
-- Get compact view of changes
SELECT
id,
commit1,
commit2,
CASE
WHEN added IS NULL THEN 'No additions'
ELSE added
END AS added_fields,
CASE
WHEN removed IS NULL THEN 'No removals'
ELSE removed
END AS removed_fields,
CASE
WHEN changed IS NULL THEN 'No changes'
ELSE changed
END AS modified_fields
FROM
chrondb_diff('user', '1', 'abc123def456', 'def456abc123');