kotlin-exposed-patterns

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

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill kotlin-exposed-patterns-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kotlin-exposed-patterns
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/kotlin-exposed-patterns
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill kotlin-exposed-patterns-freedom909

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 done from scratch. This Skill provides ready-to-apply patterns for the JetBrains Exposed ORM so you can build a consistent, coroutine-safe data layer quickly. ## Core Features & Use Cases - DSL and DAO Query Patterns: Write CRUD operations, joins, aggregations, subqueries, pagination, batch inserts, and upserts using either Exposed's SQL-like DSL or its entity-based DAO style. - Production Database Setup: Configure HikariCP connection pooling, run versioned Flyway migrations at startup, and define tables with JSONB columns via kotlinx.serialization. - Repository Pattern & Testing: Wrap Exposed queries behind repository interfaces and test them against an in-memory H2 database in PostgreSQL compatibility mode. - Use Case: You are building a Ktor service backed by PostgreSQL. Use this Skill to scaffold the UsersTable definition, a paginated ExposedUserRepository, Flyway migration scripts, and H2-based unit tests in one pass. ## Quick Start Ask the AI to create an Exposed repository with HikariCP configuration and Flyway migrations for a PostgreSQL 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 ORM in Kotlin?▼

Exposed offers two styles: the DSL uses selectAll().where { } expressions that mirror SQL directly, while the DAO style uses entity classes like UserEntity.find { } for lifecycle-managed objects. Use DSL for simple queries and DAO when you need entity relationships and change tracking.

How to set up HikariCP connection pooling with Exposed?▼

Create a HikariConfig with your JDBC URL, credentials, and maximumPoolSize, set isAutoCommit to false, then pass a HikariDataSource to Database.connect(). This gives Exposed a managed pool of reusable connections with transaction isolation control.

Does Exposed support Kotlin coroutines for database transactions?▼

Yes, Exposed provides newSuspendedTransaction, which runs database operations on a coroutine-friendly dispatcher without blocking threads. All suspend repository functions should wrap their queries in this block for atomicity and coroutine safety.

How do I run Flyway migrations in a Kotlin application?▼

Configure Flyway with your data source URL and credentials, point locations 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 automatically.

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 while matching PostgreSQL behavior closely.

When should I use Exposed DSL vs DAO pattern?▼

Use the DSL for direct SQL-like operations such as batch inserts, aggregations, and complex joins where you control every expression. Use the DAO when you need entity lifecycle management, relationships via referrersOn, and automatic dirty-field tracking on updates.