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

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.

主站蜘蛛池模板: 屏东县| 西畴县| 迁西县| 青阳县| 渭南市| 堆龙德庆县| 自治县| 柘荣县| 盐边县| 西宁市| 平潭县| 丰顺县| 伊吾县| 资阳市| 沈丘县| 屯昌县| 囊谦县| 昭苏县| 顺义区| 师宗县| 临潭县| 启东市| 获嘉县| 阿克苏市| 清水县| 平凉市| 金沙县| 苍梧县| 关岭| 从江县| 吴忠市| 台州市| 丰原市| 文昌市| 洞口县| 苍南县| 唐山市| 夏河县| 湘西| 页游| 绥阳县|