transaction(database) {
val conn = TransactionManager.current().connection
val query = "update user set name = ? where id = ?";
val statement = conn.prepareStatement(query, false)
statement.fillParameters(listOf(Pair(VarCharColumnType(), "Laura"),
Pair(IntegerColumnType(), 3)));
statement.executeUpdate()
}
fun <T : Any> String.execAndMap(transform: (ResultSet) -> T): List<T> {
val result = arrayListOf<T>()
TransactionManager.current().exec(this) { rs ->
while (rs.next()) {
result += transform(rs)
}
}
return result
}
"select u.name, c.name from user u inner join city c where blah blah".execAndMap { rs ->
rs.getString("u.name") to rs.getString("c.name")
}
5条答案
按热度按时间6ovsh4lw1#
Exposed具有
Transaction.exec(String)
方法,它可能会执行您想要的操作。rdlzhqv92#
在Kiskae答案的帮助下,我能够运行原始sql:
35g0bw713#
imzjd6km4#
下面是一个带有参数的示例:
yv5phkfx5#
您可以创建一个简单的辅助函数,如:
摘自:https://github.com/JetBrains/Exposed/wiki/FAQ#q-is-it-possible-to-use-native-sql--sql-as-a-string