-
原谅我是新手,之前一直使用java+mybatis或jpa,看到ktorm的文发现有所见即所得的感觉想尝试一下,奈何基本没接触过kotlin,我尝试在quarkus+kotlin初始项目中,按照文档使用,但是貌似不起作用 引入 implementation("org.ktorm:ktorm-core:${ktOrmVersion}")
implementation("org.ktorm:ktorm-support-mysql:${ktOrmVersion}")
implementation("io.quarkus:quarkus-jdbc-mysql") 定义数据源quarkus.datasource.jdbc.url=jdbc:mysql://127.0.0.1:3306/demo
quarkus.datasource.username=root
quarkus.datasource.password=root 配置class KtOrmConfiguration {
@ConfigProperty(name = "quarkus.datasource.jdbc.url")
lateinit var url: String
@ConfigProperty(name = "quarkus.datasource.username")
lateinit var username: String
@ConfigProperty(name = "quarkus.datasource.password")
lateinit var password: String
@Produces
@ApplicationScoped
fun database(): Database {
return Database.connect(url, username, password)
}
} 实体类object User : Table<Nothing>("user") {
val id = long("id").primaryKey()
val avatarUrl = varchar("avatar_url")
val nickName = varchar("nick_name")
} 使用@Path("/hello")
class ExampleResource {
@Inject
lateinit var database: Database
@GET
@Path("all")
fun all() {
for (row in database.from(User).select()) {
println(row[User.nickName])
}
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
seepine
Aug 30, 2022
Replies: 1 comment
-
不好意思,照抄文档快速入门的代码没看源码,点进去connect才发现,第二个传递的是driver,修改后可以了
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
seepine
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
不好意思,照抄文档快速入门的代码没看源码,点进去connect才发现,第二个传递的是driver,修改后可以了