Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsMay 23, 2026·3 min de lecture

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.

Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Exposed Overview
Commande CLI universelle
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

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires