kotlin-exposed-patterns

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

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill kotlin-exposed-patterns-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-exposed-patterns
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/kotlin-exposed-patterns
Command: npx skills add https://github.com/Femad-6/my-skills --skill kotlin-exposed-patterns-femad-6

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Setting up database access in Kotlin backend services requires coordinating ORM queries, connection pooling, schema migrations, and transaction management, which is error-prone when assembled from scratch. ## Core Features & Use Cases - Exposed DSL and DAO Patterns: Write type-safe SQL queries using either the DSL style for direct expressions or the DAO style for entity lifecycle management. - Production Database Setup: Configure HikariCP connection pooling and run versioned Flyway migrations at application startup. - Repository Pattern with Testing: Wrap Exposed queries behind repository interfaces and test them against an in-memory H2 database. - Use Case: When building a Ktor backend that needs user and order persistence, use this Skill to define UUID tables, write paginated queries with joins, and wire up migrations and pooling in one consistent structure. ## Quick Start Use the kotlin-exposed-patterns skill to set up an Exposed repository with HikariCP pooling and Flyway migrations for a users table.

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 { } for direct SQL-like expressions, while the DAO style uses entity classes like UserEntity.find { } for lifecycle-managed objects. Wrap all operations in newSuspendedTransaction for coroutine safety.

Exposed DSL vs DAO pattern, which should I use?

Use the DSL style for simple, direct queries where you map ResultRow objects manually. Use the DAO style when you need entity lifecycle management, relationships via referrersOn, and property delegation to table columns.

How do I run database migrations with Exposed and Flyway?

Configure Flyway with your JDBC URL and credentials, point it to 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 support coroutines and suspend functions?

Yes, Exposed provides newSuspendedTransaction, which runs database operations inside a coroutine-safe transaction block. All suspend repository functions should use it instead of the blocking transaction function.

How do I test Exposed repositories without a real database?

Connect Exposed to an in-memory H2 database with PostgreSQL compatibility mode, create tables with SchemaUtils.create, and clean data between tests with deleteAll. This lets repository tests run without external infrastructure.

How do I store JSON columns in Exposed with PostgreSQL?

Define a custom jsonb column type using registerColumn with a ColumnType that serializes values via kotlinx.serialization and wraps them in PGobject. The column can then be declared nullable on any table.