0Pricing
Kotlin Academy · Lesson

CRUD with the Query DSL: insert, select, update, delete

Perform all CRUD operations using Exposed's type-safe query DSL.

Query DSL Overview

Exposed's Query DSL lets you write typesafe SQL operations using Kotlin functions. All operations are performed inside a transaction { } block. There are no magic strings — column references are Kotlin properties, so typos are caught at compile time.

Insert

Use Table.insert { } to add a row. The lambda receives an InsertStatement and you set column values using the [column] operator:

transaction {
    Users.insert {
        it[Users.name]  = "Alice"
        it[Users.email] = "alice@example.com"
        it[Users.age]   = 30
    }
}

All lessons in this course

  1. Exposed Setup: Database Connection and Transaction DSL
  2. Defining Tables with the Table DSL
  3. CRUD with the Query DSL: insert, select, update, delete
  4. Exposed DAO: Entity Classes and Relationships
← Back to Kotlin Academy