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

  • Kotlin Blueprints
  • Ashish Belagali Hardik Trivedi Akshay Chordiya
  • 182字
  • 2021-07-02 21:50:14

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.

主站蜘蛛池模板: 论坛| 庆云县| 垣曲县| 德清县| 湖州市| 武山县| 德阳市| 梧州市| 长春市| 白河县| 江门市| 故城县| 兴国县| 报价| 巴中市| 宁德市| 岗巴县| 灌南县| 通海县| 河北省| 武平县| 陆丰市| 银川市| 顺义区| 成武县| 惠东县| 澄城县| 青川县| 龙里县| 哈密市| 宕昌县| 客服| 嘉义市| 黄陵县| 厦门市| 汪清县| 卢龙县| 隆尧县| 太和县| 营口市| 神池县|