This directory contains example applications demonstrating the Datahike Java API.
- Java 17 or higher (required for text blocks and modern Java features)
- Maven 3.6+
Run examples directly with Maven:
# Quick Start
mvn compile exec:java -Dexec.mainClass="examples.QuickStart"
# Schema Example
mvn compile exec:java -Dexec.mainClass="examples.SchemaExample"
# Time Travel Example
mvn compile exec:java -Dexec.mainClass="examples.TimeTravelExample"Build the project and run the JAR:
# Build
mvn clean package
# Run (using QuickStart as main class from pom.xml)
java -jar target/datahike-java-examples-1.0.0-SNAPSHOT.jar
# Or run specific examples
java -cp target/datahike-java-examples-1.0.0-SNAPSHOT.jar examples.SchemaExampleImport the Maven project into your IDE (IntelliJ IDEA, Eclipse, VSCode) and run the main classes directly.
Basic introduction to Datahike:
- Database configuration with builder pattern
- Creating and connecting to databases
- Transacting data with Java Maps
- Querying with Datalog
- Updates and cleanup
Key concepts: Builder pattern, basic queries, CRUD operations
Schema definition and validation:
- Defining attributes with type constraints
- Unique constraints (identity vs value)
- Reference types for relationships
- Cardinality (one vs many)
- Using Keywords constants
Key concepts: Schema definition, relationships, data validation
Historical queries and time travel:
- Querying database state at specific points in time
- Using
asOffor point-in-time queries - Using
sincefor change tracking - Querying full history
- Transaction metadata
Key concepts: Immutability, history, audit trails
examples/java/
├── pom.xml # Maven configuration
├── README.md # This file
└── src/main/java/examples/
├── QuickStart.java # Basic usage
├── SchemaExample.java # Schema definition
└── TimeTravelExample.java # Time travel queries
To use Datahike in your own Maven project, add to your pom.xml:
<repositories>
<repository>
<id>clojars</id>
<url>https://repo.clojars.org/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.replikativ</groupId>
<artifactId>datahike</artifactId>
<version>LATEST_VERSION</version>
</dependency>
</dependencies>For Gradle:
repositories {
maven { url "https://repo.clojars.org/" }
}
dependencies {
implementation 'io.replikativ:datahike:LATEST_VERSION'
}Note: Replace LATEST_VERSION with the latest published version from Clojars.
Datahike- Main API with all database operationsDatabase- Fluent builder for configurationKeywords- Pre-defined constants for schemaSchemaFlexibility- Enum for schema modesUtil- Low-level utilities (map, vec, kwd)EDN- EDN data type constructors
- Java API Documentation - Comprehensive API guide
- Main README - Project overview
- Schema Guide - Detailed schema documentation
- Storage Backends - Backend configuration
- Datalog Tutorial - Query language
Build fails with "Could not find artifact"
- Ensure Clojars repository is configured
- Check internet connection
- Try
mvn clean install -Uto force update
Runtime errors about Clojure
- Datahike includes Clojure as a dependency
- Check for dependency conflicts with
mvn dependency:tree
ClassCastException in query results
- Query results are Clojure collections (Set, List, Map)
- Cast appropriately:
(Set<?>) Datahike.q(...)
Eclipse Public License 1.0 (EPL-1.0)