ConfigsMay 23, 2026·3 min read

Exposed — Kotlin SQL Framework with Type-Safe DSL and DAO

Exposed is a Kotlin SQL library by JetBrains offering two flavors: a lightweight type-safe DSL for SQL queries and a full DAO layer with entity mapping, both supporting multiple database backends.

Agent ready

This asset can be read and installed directly by agents

TokRepo exposes a universal CLI command, install contract, metadata JSON, adapter-aware plan, and raw content links so agents can judge fit, risk, and next actions.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
Exposed Overview
Universal CLI install command
npx tokrepo install a8db759c-5660-11f1-9bc6-00163e2b0d79

Introduction

Exposed is an open-source SQL framework developed by JetBrains for Kotlin. It provides two complementary access layers: a typesafe DSL that mirrors SQL syntax in Kotlin code, and a DAO layer for lightweight ORM-style entity management. Both approaches leverage Kotlin's type system to catch query errors at compile time.

What Exposed Does

  • Provides a typesafe DSL where table columns, joins, and conditions are Kotlin expressions
  • Offers a DAO layer mapping database rows to Kotlin objects with lazy loading
  • Manages database transactions with automatic commit, rollback, and retry
  • Supports schema generation and migration through SchemaUtils
  • Works with PostgreSQL, MySQL, MariaDB, SQLite, H2, Oracle, and SQL Server

Architecture Overview

Exposed defines tables as Kotlin objects extending Table. Columns are properties with types that enforce compile-time safety. The DSL layer translates Kotlin expressions into SQL strings via a dialect abstraction, while the DAO layer wraps rows in Entity objects backed by an identity map within the transaction scope. Connection pooling integrates with HikariCP or any JDBC DataSource.

Installation & Configuration

  • Add exposed-core, exposed-dao, and exposed-jdbc modules via Gradle or Maven
  • Configure a Database.connect() call with JDBC URL, driver, and credentials
  • Optionally add exposed-java-time or exposed-kotlin-datetime for date column support
  • Use exposed-spring-boot-starter for automatic Spring Boot integration
  • Set TransactionManager.defaultDatabase for implicit transaction binding

Key Features

  • Compile-time SQL validation eliminates entire classes of runtime query errors
  • DSL queries compose naturally with Kotlin's let, apply, and extension functions
  • DAO entities support one-to-many and many-to-many relations via referencedOn and via
  • Batch insert and upsert operations for efficient bulk data loading
  • Coroutine-friendly with newSuspendedTransaction for non-blocking database access

Comparison with Similar Tools

  • Hibernate/JPA — annotation-heavy ORM with XML config; Exposed uses Kotlin DSL for lighter, more idiomatic code
  • jOOQ — Java-first SQL builder with code generation; Exposed is Kotlin-native and needs no code generation step
  • Ktorm — similar Kotlin ORM; Exposed has broader database support and is maintained by JetBrains
  • SQLDelight — generates Kotlin from SQL files; Exposed lets you write queries in Kotlin directly
  • Spring Data JPA — repository-based abstraction; Exposed gives finer SQL control with less magic

FAQ

Q: Can Exposed handle database migrations? A: SchemaUtils.createMissingTablesAndColumns() handles simple schema evolution. For production migrations, pair it with Flyway or Liquibase.

Q: Does Exposed support connection pooling? A: Yes. Pass a HikariCP DataSource to Database.connect() for production-grade connection management.

Q: Is Exposed suitable for large-scale applications? A: Yes. JetBrains uses it in their own products. The DSL layer generates efficient SQL, and batch operations handle high-throughput scenarios.

Q: Can I use raw SQL with Exposed? A: Yes. exec() and TransactionManager.current().exec() let you run arbitrary SQL when the DSL does not cover a specific need.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets