Slick 3.0.0从表中删除所有条目(Slick 3.0.0 Delete all Entries From a Table)

编程入门 行业动态 更新时间:2024-10-07 23:15:57
Slick 3.0.0从表中删除所有条目(Slick 3.0.0 Delete all Entries From a Table)

以下查询:

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.

更多推荐

本文发布于:2023-08-04 02:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408611.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条目   Slick   Table   Entries   Delete

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!