explaingit

jetbrains/exposed

9,236KotlinAudience · developerComplexity · 3/5LicenseSetup · moderate

TLDR

An official JetBrains database library for Kotlin that lets you query relational databases using type-safe Kotlin code instead of raw SQL strings, with both a DSL style and an object-mapping style.

Mindmap

mindmap
  root((Exposed))
    What it does
      Kotlin database library
      SQL abstraction layer
      Type-safe queries
    Query styles
      DSL queries
      DAO object mapping
      Mixed approach
    Databases supported
      PostgreSQL
      MySQL
      SQLite
      SQL Server
    Modules
      Core module
      JDBC transport
      R2DBC reactive
      Spring Boot integration
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Replace raw SQL strings in a Kotlin backend with type-safe DSL queries checked by the compiler

USE CASE 2

Map database rows to Kotlin objects using the DAO style to work with records as class instances

USE CASE 3

Switch a Kotlin app from SQLite to PostgreSQL with minimal code changes using Exposed's shared abstraction layer

USE CASE 4

Add Exposed to a Spring Boot project using the optional integration module for managed database access

Tech stack

KotlinJDBCR2DBCSQLGradleSpring Boot

Getting it running

Difficulty · moderate Time to first run · 30min

Requires a running database instance (PostgreSQL, MySQL, etc.) and the corresponding JDBC driver dependency.

Free to use, modify, and distribute for any purpose including commercial use, attribution is not required.

In plain English

Exposed is a database library for the Kotlin programming language, created by JetBrains. Its job is to let Kotlin programs talk to relational databases without requiring developers to write raw SQL strings scattered throughout their code. Instead, database queries are written using Kotlin syntax that the library translates into the appropriate SQL for whichever database the application is connected to. The library offers two distinct styles for working with data. The first is a DSL, short for Domain-Specific Language, which lets you describe queries and table operations using Kotlin code that closely resembles SQL but is checked by the compiler for correctness. The second is a DAO style, short for Data Access Object, which maps database rows to Kotlin objects so you can work with data as if it were regular class instances rather than table rows. You pick whichever approach suits your project, or mix them. Exposed works with several widely used databases: H2, MySQL, MariaDB, PostgreSQL, Oracle, Microsoft SQL Server, and SQLite. Because queries go through a shared abstraction layer, the goal is that switching from one database to another requires little to no changes in your application code. The library supports both the traditional JDBC connection approach and R2DBC, a newer reactive driver standard suited to non-blocking applications. The library is organized into separate modules you pull in depending on what you need. The core module is always required. You add the JDBC or R2DBC transport module based on your connection approach. Optional extension modules cover things like date and time handling, encrypted column storage, JSON column types, monetary amounts, and integration with Spring Boot if you are using that framework. Exposed is an official JetBrains project, available through the Maven Central package repository, and released under the Apache 2.0 license. A Slack channel and dedicated documentation site support people using it.

Copy-paste prompts

Prompt 1
Using JetBrains Exposed DSL, show me how to define a Users table with id, name, and email columns, then write a query that selects all users where the email ends in @example.com.
Prompt 2
With Exposed DAO style, show me how to map a database table to a Kotlin Entity class and insert a new row using idiomatic Kotlin.
Prompt 3
How do I add the jetbrains/exposed core and PostgreSQL JDBC modules to a Kotlin Gradle project and open a database connection?
Prompt 4
Using Exposed, show me how to perform a left join between two tables and map the results into a list of Kotlin data objects.
Prompt 5
How do I use the Exposed Spring Boot starter to configure a database connection in application.properties?
Open on GitHub → Explain another repo

← jetbrains on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.