以下查询:
val resultValue = Await.result(db.run(MyTable.myTableItems.delete), 2.seconds)奇怪的是,运行时的上述查询给出了我在该特定表中的Id的最大值。 这是为什么? 从表中删除所有条目的Slick相当于什么?
The following query:
val resultValue = Await.result(db.run(MyTable.myTableItems.delete), 2.seconds)Strangely, the above query when run gives me the max value for the Id that I have in that particular table. Why is that? What is the Slick equivalent of delete all entries from a Table?
最满意答案
delete的结果是受删除影响的行数。 如果你的id从1开始,那么受影响的行数恰好与表中的最大id相同可能是巧合。
在表查询上调用delete是从表中删除所有条目的方法。 例如,如果你有
val coffees = TableQuery[Coffees]...然后coffees.delete是删除所有行的操作。
有用的链接:在Slick手册中删除 。
The result from delete is the number of rows affected by the delete. If your id starts from 1, it could be a coincidence that the number of rows affected happens to be the same as largest id in the table.
Calling delete on a table query is the way to delete all entries from a table. For example, if you have
val coffees = TableQuery[Coffees]...then coffees.delete is the action to remove all rows.
Useful link: Deleting, in the Slick Manual.
更多推荐
发布评论