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

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.

主站蜘蛛池模板: 科技| 措美县| 五家渠市| 郓城县| 抚宁县| 界首市| 乌鲁木齐县| 炉霍县| 全椒县| 得荣县| 抚宁县| 沾化县| 巴彦淖尔市| 孝昌县| 宝丰县| 株洲市| 遂平县| 松江区| 南康市| 多伦县| 龙井市| 孟津县| 太和县| 昭觉县| 疏勒县| 哈尔滨市| 乌鲁木齐县| 德兴市| 侯马市| 怀化市| 梧州市| 龙南县| 马鞍山市| 玛多县| 晋州市| 荣昌县| 卫辉市| 辽阳市| 张家口市| 香港 | 会同县|