kotlin-exposed-patterns

Implements database access patterns with JetBrains Exposed ORM, HikariCP pooling, and Flyway migrations.

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill kotlin-exposed-patterns-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-exposed-patterns
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/kotlin-exposed-patterns
Command: npx skills add https://github.com/ibytechaos/claude --skill kotlin-exposed-patterns-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Setting up database access in Kotlin backend services involves many decisions: choosing between DSL and DAO query styles, configuring connection pooling, managing schema migrations, and structuring testable data layers. This Skill provides production-oriented patterns for all of these with JetBrains Exposed ORM. ## Core Features & Use Cases - DSL and DAO Query Patterns: Covers CRUD operations, joins, aggregations, subqueries, pagination, batch inserts, and upserts using both Exposed DSL and DAO entity styles. - Production Database Setup: Includes HikariCP connection pool configuration, Flyway versioned migrations, and coroutine-safe transactions via newSuspendedTransaction. - Repository Pattern & Testing: Shows how to wrap Exposed behind a repository interface and test against an in-memory H2 database in PostgreSQL compatibility mode. - Use Case: When building a Ktor or Spring-less Kotlin service backed by PostgreSQL, use this Skill to scaffold the table definitions, repository layer, migrations, and tests in one consistent style. ## Quick Start Ask the AI to set up an Exposed-based user repository with HikariCP pooling, Flyway migrations, and H2-backed tests for a Kotlin project.

Frequently Asked Questions about kotlin-exposed-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write queries with JetBrains Exposed in Kotlin?

Exposed offers two styles: the DSL style uses Table.selectAll().where { } with type-safe column expressions, while the DAO style uses entity classes like UserEntity.find { }. Both run inside newSuspendedTransaction blocks for coroutine-safe execution.

Exposed DSL vs DAO: which should I use?

Use the DSL style for simple, direct SQL-like queries and batch operations. Use the DAO style when you need entity lifecycle management, relationships via referrersOn, and object-oriented mutation of rows.

How do I run database migrations with Exposed and Flyway?

Configure Flyway with your JDBC URL and credentials, point it at classpath:db/migration, and call migrate() at application startup before connecting Exposed. Versioned SQL files like V1__create_users.sql keep the schema in sync.

Does Exposed work with Kotlin coroutines?

Yes, Exposed supports coroutines through newSuspendedTransaction, which runs blocking JDBC operations on an appropriate dispatcher. All suspend repository functions should wrap their queries in this block for atomicity and thread safety.

How do I test Exposed repositories without a real database?

Connect Exposed to an in-memory H2 database using jdbc:h2:mem:test with MODE=PostgreSQL, create tables via SchemaUtils.create, and clean rows between tests. This lets repository tests run fast without a live PostgreSQL instance.

How do I store JSON columns in PostgreSQL with Exposed?

Define a custom jsonb column type using kotlinx.serialization that converts values to and from PGobject with type jsonb. Register it on the table with registerColumn, then use it like any other column, optionally marked nullable.