我正在尝试将简单INSERT INTO...SELECT FROM
的查询翻译成 Quill 中的报价。首先,我没有找到一种内置的方法来做到这一点,所以最终尝试使用中缀查询
val rawQuery = quote { (secondTableValues: List[Int]) => {
infix"""
INSERT INTO my_table (second_table_id)
VALUES (
${secondTableValues.map(stid => (SELECT id FROM second_table where id = $stid)).mkString(",")}}
)
""".as[Insert[Any]]
}}
databaseClient.run(rawQuery(List(1,2,3)))
但是,这不会编译,因为 Quill 无法为查询构建 Ast。
我最终做的是有一个原始查询而不是使用引号并使用executeAction
.
所以两个问题
- 您将如何
INSERT INTO...SELECT FROM
以内置方式进行操作? - 上面的版本有什么问题
infix
?