Examples
Explore real-world examples of using Kapper in various scenarios. All examples include complete, runnable code that you can use as a starting point for your own projects.
Quick Navigation
Kotlin Examples
Java Examples
Framework Comparisons
Database Schema
All examples use a superhero-themed database schema:
sql
CREATE TABLE super_heroes (
id UUID PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255),
age INT
);
CREATE TABLE villains (
id UUID PRIMARY KEY,
name VARCHAR(255) NOT NULL
);
CREATE TABLE battles (
super_hero_id UUID REFERENCES super_heroes(id),
villain_id UUID REFERENCES villains(id),
battle_date TIMESTAMP NOT NULL,
updated_ts TIMESTAMP NOT NULL,
PRIMARY KEY (super_hero_id, villain_id, battle_date)
);Database setup scripts are available for:
Project Structure
The complete examples are available in the examples directory of the main repository:
examples/
├── kotlin-example/ # Kotlin examples and tests
├── java-example/ # Java examples and tests
├── db/ # Database setup scripts
└── docs/ # Blog posts and additional documentationRunning the Examples
Clone the repository:
bashgit clone https://github.com/driessamyn/kapper.git cd kapper/examplesSet up your database using the scripts in
/dbRun the examples:
bash# Kotlin examples ./gradlew :kotlin-example:test # Java examples ./gradlew :java-example:test
Key Concepts Demonstrated
- Auto-mapping: How Kapper automatically maps SQL results to Kotlin data classes and Java records
- Parameter binding: Different ways to pass parameters to SQL queries
- Transaction handling: Managing database transactions effectively
- Error handling: Proper exception handling and resource management
- Performance patterns: Writing efficient queries and bulk operations
- Database compatibility: Working with different database engines
Ready to dive in? Start with Basic CRUD Operations or jump to any specific example that interests you.
