gpt4 book ai didi

scala - 如何在 Lift(Scala 的 Web 框架)中计算行数

转载 作者:行者123 更新时间:2023-12-04 18:54:59 24 4
gpt4 key购买 nike

我想向我的 User 模型添加一个属性,该属性返回 Project 表中具有用户用户 ID 的行数。

所以像这样的事情......

def numProjects = {

/* somehow get count from Project table
The straight sql would be:
SELECT COUNT(*) FROM projects WHERE userId = <the current user>

*/

}

最佳答案

根据文档 here (找到 here ),假设您正在查找 ID 为 1234 的用户的项目计数并假设您的项目模型继承了 MetaMapper 特征(可能通过 KeyedMetaMapper),您似乎可以使用 count 方法:

Project.count(By(User.id, 1234))

或者
Project.count(BySql("userId = ?", 1234))

我无法测试,因为我还没有使用过 Lift,但它看起来不错...... :) 让我知道它是否有效!

关于scala - 如何在 Lift(Scala 的 Web 框架)中计算行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/118750/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com