Exposed 1.0: A Major Milestone for the Kotlin SQL Framework (opens in new tab)

Exposed 1.0: A Major Milestone for the Kotlin SQL Framework

The Exposed team is thrilled to announce the release of Exposed 1.0, a significant milestone for the Kotlin SQL framework. This major release brings numerous exciting features, performance enhancements, and bug fixes, making it a must-have for Kotlin developers working with databases. In this article, we’ll dive into the details of Exposed 1.0 and explore its new features, improvements, and best practices.

What’s New in Exposed 1.0?

Exposed 1.0 is the result of extensive development and community feedback. The most notable feature in this release is the addition of R2DBC support. R2DBC (Reactive Relational Database Connectivity) is a reactive database connectivity specification that allows for non-blocking, asynchronous database interactions. With Exposed 1.0, developers can now leverage R2DBC to build more responsive and scalable applications.

R2DBC Support

To use R2DBC with Exposed 1.0, you’ll need to add the exposed-r2dbc module to your project. Here’s an example of how to do this in Gradle:

dependencies {
implementation 'org.jetbrains.exposed:exposed-r2dbc:1.0.0'
}

With R2DBC support, you can now write reactive database code using Exposed’s familiar API. Here’s an example of how to perform a simple query using R2DBC:

import org.jetbrains.exposed.r2dbc.R2dbcDatabase
import org.jetbrains.exposed.sql.select

// Create an R2DBC database instance
val database = R2dbcDatabase.connect("r2dbc:postgresql://localhost:5432/mydb", "username", "password")

// Perform a query using Exposed's DSL
database.transaction {
val results = Users.select { Users.name eq "John" }.toList()
results.forEach { println(it[Users.name]) }
}

Performance Enhancements

Exposed 1.0 also brings significant performance improvements, particularly in the areas of query generation and database interaction. These enhancements result in faster and more efficient database operations, making your applications more responsive and scalable.

Improved Query Generation

Exposed’s query generation has been optimized to reduce the number of database queries and improve overall performance. Here’s an example of how Exposed’s DSL can be used to generate efficient queries:

import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.join

// Define two tables
object Users : Table() {
val id = integer("id").autoIncrement().primaryKey()
val name = varchar("name", 255)
}

object Orders : Table() {
val id = integer("id").autoIncrement().primaryKey()
val userId = integer("user_id").references(Users.id)
}

// Perform a join using Exposed's DSL
val results = Users.join(Orders, JoinType.INNER, Users.id, Orders.userId)
.select { Users.name eq "John" }
.toList()

Bug Fixes and Stability Improvements

Loading more...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help