Takeaway From This article

In my experience, writing and executing queries requires careful analysis. Writing custom queries is possible but complicated. If you’re using Kotlin, then using Exposed is your solution. In this article, you’re going to learn how to create database tables and how to perform CURD operations on them.

Introduction

Exposed is a lightweight SQL library from JetBrains, written in pure Kotlin. I found it when I was looking for a simple SQL library to handle databases in a server-side application using Ktor.

Exposed is an ORM framework for Kotlin. It offers two levels of database access: type-safe SQL-wrapping DSL and lightweight data-access objects. In this article, we’re going to discuss the first approach using Kotlin DSL.

Exposed can act as a middle layer to connect numerous database engines and to write tedious queries in a different approach via the fancy Kotlin DSL language. H2, MySQL, MariaDB, and PostgreSQL are some of the databases that Exposed supports.

Integration

Enough with the talk; let’s get started with the integration part. Add the following line under the dependencies tag in the build.gradle file to import Exposed to your project.

implementation("org.jetbrains.exposed:exposed:0.12.1")

Coming to the database part, in this example, we use the H2 database. To import it, add the following line:

implementation("com.h2database:h2:1.4.191")

That’s all. We’re done with the integration part.

#kotlin #sql #database #android

Exposed — A Lightweight Kotlin SQL Library
4.70 GEEK