官术网_书友最值得收藏!

CRUD operations

The following code snippet shows an example of how to do create, read, update, delete (CRUD) operations with Exposed:

    transaction {

// Insert new message Messages.insert {
it[name] = "Hello Kotlin Developers!"
}

// Update an existing message
Messages.update({Users.id eq 1}) {
it[name] = "Hello Spring-Kotlin Developers"
}
// Delete the messages table drop(Messages) }

It results in the following queries:

    INSERT INTO Messages (name) VALUES ('Hello Kotlin Developers!')
UPDATE Messages SET name='Hello Spring-Kotlin Developers' WHERE
Messages.id = 1
DROP TABLE Messages

Get all the users from the database:

    for (message in Messages.selectAll()) {
println("$message[Messages.name]}")
}

It will result in the following query:

    SELECT Messages.name FROM Messages;

Now it must be pretty clear how to use the Exposed library for Spring and how it works internally.

The reason for using the Exposed library instead of Spring JPA is because, at the time of writing, there is no official support for Kotlin data classes and JPA, that is Spring Data JPA.  JetBrains noticed this and they released their own SQL ORM library called Exposed.
Read more at https://github.com/JetBrains/Exposed.

主站蜘蛛池模板: 兴山县| 汾阳市| 准格尔旗| 哈巴河县| 柏乡县| 中牟县| 东丰县| 梓潼县| 改则县| 温宿县| 辽阳县| 南汇区| 朝阳市| 任丘市| 乐都县| 皋兰县| 阿克陶县| 蒲城县| 内江市| 长垣县| 张家界市| 谢通门县| 两当县| 河池市| 信丰县| 太谷县| 绥化市| 尚义县| 井研县| 开封县| 丹东市| 波密县| 靖远县| 泗阳县| 鹤峰县| 甘肃省| 仙桃市| 保德县| 河源市| 博湖县| 江都市|