gitmyhub

Exposed

Kotlin ★ 9.3k updated 2d ago

Kotlin SQL Framework

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.

KotlinJDBCR2DBCSQLGradleSpring Bootsetup: moderatecomplexity 3/5

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.

Where it fits