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
- Exposed Setup: Database Connection and Transaction DSL
- Defining Tables with the Table DSL
- CRUD with the Query DSL: insert, select, update, delete
- Exposed DAO: Entity Classes and Relationships