Protocols Overview

ChronDB supports multiple access protocols, allowing integration with different clients and frameworks.

REST API

ChronDB provides a complete REST API for database operations.

Configuration

In the config.edn file:

:servers {
  :rest {
    :enabled true
    :host "0.0.0.0"
    :port 3000
  }
}

Endpoints

Documents

Method
Endpoint
Description

GET

/api/v1/documents/:key

Get document by key

POST

/api/v1/documents/:key

Create/update document

DELETE

/api/v1/documents/:key

Delete document

GET

/api/v1/documents/:key/history

Get document history

GET

/api/v1/documents/:key/at/:timestamp

Get document at a point in time

Method
Endpoint
Description

GET

/api/v1/search?q=query

Search documents

Branches

Method
Endpoint
Description

GET

/api/v1/branches

List branches

POST

/api/v1/branches/:name

Create branch

PUT

/api/v1/branches/:name/checkout

Switch to branch

POST

/api/v1/branches/:source/merge/:target

Merge branches

Example with curl

Redis Protocol

ChronDB implements a subset of the Redis protocol, allowing Redis clients to connect directly.

Configuration

In the config.edn file:

Supported Commands

Command
Description

GET key

Get document by key

SET key value

Create/update document

DEL key

Delete document

KEYS pattern

List keys matching the pattern

HGET key field

Get specific field from document

HSET key field value

Set specific field in document

CHRONDB.HISTORY key

Get document history

CHRONDB.GETAT key timestamp

Get document at a point in time

CHRONDB.DIFF key t1 t2

Compare document versions

Example with redis-cli

PostgreSQL Protocol

ChronDB implements a subset of the PostgreSQL protocol, allowing connection with SQL clients.

Configuration

In the config.edn file:

Data Model

Documents are mapped to virtual tables based on their keys:

  • Prefix before : becomes the table name

  • Document fields become columns

For example, the key user:1 with document {"name":"John","email":"[email protected]"} is accessible as:

SQL Features

Feature
Description

SELECT

Query documents

INSERT

Create documents

UPDATE

Update documents

DELETE

Delete documents

CREATE TABLE

Create collection (optional, schemas are inferred)

Special Functions

Function
Description

chrondb_history(table, id)

Get document history

chrondb_at(table, id, timestamp)

Get document at a point in time

chrondb_diff(table, id, t1, t2)

Compare document versions

SQL History Functions

ChronDB provides specialized SQL functions to access the version history of documents:

chrondb_history(table_name, document_id)

Returns the complete modification history of a document.

Result columns:

  • commit_id: Commit hash identifying the version

  • timestamp: When the change was made

  • committer: Who made the change

  • data: Document content at that version

Example:

chrondb_at(table_name, document_id, commit_hash)

Returns the document exactly as it was at a specific commit.

Example:

chrondb_diff(table_name, document_id, commit_hash1, commit_hash2)

Compares two versions of a document and returns the differences.

Result columns:

  • id: The document ID

  • commit1: First commit hash used in comparison

  • commit2: Second commit hash used in comparison

  • added: Fields added between versions (JSON format)

  • removed: Fields removed between versions (JSON format)

  • changed: Fields modified between versions (JSON format with old and new values)

Example:

Example with psql

Last updated