我已经研究了如何使用squeryl删除表中的所有记录。 我唯一能想到的就是
myTable.deleteWhere(r => r.id.isNotNull) //id is the primary key这看起来很奇怪,也可能效率低下。
使用squeryl时从表中删除所有记录的最简洁方法是什么?
I've looked at ways to use squeryl to delete all records from a table. The only thing I could come up with is
myTable.deleteWhere(r => r.id.isNotNull) //id is the primary keyThis seems strange and possibly inefficient.
What is the cleanest way to delete all records from a table when using squeryl?
最满意答案
deleteWhere子句采用任何逻辑布尔值,因此您可以简单地说:
myTable.deleteWhere(r => 1 === 1)哪个应输出声明:
DELETE FROM mytable WHERE 1 = 1如果要自动消除where子句,可以尝试:
myTable.deleteWhere(r => 1 === 1.inhibitWhen(true))哪个应该完全压制where子句。
如果您正在寻找一种更有效的方法,并且您的数据库支持TRUNCATE或其他等效函数,您可以从org.squeryl.Session获取java.sql.Connection并直接通过JDBC发出查询。 不幸的是,这将失去一些Squeryl提供的类型安全性。
The deleteWhere clause takes any logical boolean, so you could simply say:
myTable.deleteWhere(r => 1 === 1)Which should output the statement:
DELETE FROM mytable WHERE 1 = 1If you want to eliminate the where clause automatically, you could try:
myTable.deleteWhere(r => 1 === 1.inhibitWhen(true))Which should suppress the where clause altogether.
If you are looking for an even more efficient method and your database supports TRUNCATE or another equivalent function, you can get a java.sql.Connection from org.squeryl.Session and issue the query directly through JDBC. Unfortunately, this would lose some of the type safety Squeryl offers.
更多推荐
发布评论