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

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.

主站蜘蛛池模板: 高州市| 丰台区| 新巴尔虎右旗| 周口市| 玛纳斯县| 梅河口市| 汾阳市| 辽源市| 阳泉市| 泽普县| 鹤庆县| 砀山县| 公主岭市| 古蔺县| 昌邑市| 陇西县| 濉溪县| 阳东县| 四子王旗| 南部县| 德令哈市| 怀化市| 西安市| 固阳县| 平泉县| 章丘市| 洱源县| 巨野县| 炉霍县| 两当县| 丘北县| 贺兰县| 云阳县| 贞丰县| 旅游| 伊春市| 鹿泉市| 屯门区| 定州市| 兴国县| 秦皇岛市|