Announcing Krush – idiomatic persistence layer for Kotlin, based on Exposed


We've released a persistence library for Kotlin, you can find it on our Github. It’s a JPA-to-Exposed SQL DSL generator.

The state of persistence in Kotlin

One of the key decisions that helped Kotlin gain massive popularity was to reuse Java ecosystem instead of inventing it’s own. This means that you can safely use Kotlin as a primary language for a project developed using any popular Java stack like Spring Boot and built with Java build tool like Maven. What this also means is that natural choice for persistence layer in Kotlin is Spring Data with JPA 3 with Hibernate as an implementation.

However, JPA, which highly relies on mutable objects and dirty checking, may not look like pure Kotlin, which tries to embrace functional programming and immutability. The official Spring JPA guide for Kotlin uses mutable classes and properties which is not really idiomatic for Kotlin where you want to use immutable data classes whenever it’s possible.

How we use Kotlin with Exposed at TouK

Why Kotlin?

At TouK, we try to early adopt technologies. We don’t have a starter project skeleton that is reused in every new project, we want to try something that fits the project needs, even if it’s not that popular yet. We tried Kotlin first it mid 2016, right after reaching 1.0.2 version. It was getting really popular in Android development, but almost nobody used it on the backend, especially — with production deployment. After reading some “hello world” examples, including this great article by Sebastien Deleuze we decided to try Kotlin as main language a new MVNO project. The project was mainly a backend for mobile app, with some integrations with external services (chat, sms, payments) and background tasks regarding customer’s subscription. We felt that Kotlin would be something fresh and more pleasant for developers, but also liked the “not reinventing the wheel” approach — reusing large parts of Java/JVM ecosystem we were happy with for existing projects (Spring, Gradle, JUnit, Mockito).