获取 Slick 中的最后一行
Get the last row in Slick
我有 PostgreSQL table。
消息:
|id | phone | message | login |
-----------------------------------
* |1 | 85543422 | Hello! | User1 |
|2 | 85543422 | i love | User2 |
-----------------------------------*
我需要通过 phone 值 (85543422) 过滤 table 并从最后一行获取用户名。
现在我有一个方法可以让你从第一行提取用户名。
//return "User1"
def getUserByPhone():String = {
val query = outgoing.filter(_.phone === "85543422").map(_.login).result.headOption
val result = Await.result(db.run(query), Duration.Inf)
if (result.value.isEmpty) return "None"
result.value.get
}
帮忙实现去掉最后一行用户名的方法。
我需要得到“User2”
您可以按 id desc 排序以获得最后一行的用户名
例
val query = outgoing.filter(_.phone === "85543422")
.sortBy(_.id.desc)
.map(_.login).result.headOption
我有 PostgreSQL table。
消息:
|id | phone | message | login |
-----------------------------------
* |1 | 85543422 | Hello! | User1 |
|2 | 85543422 | i love | User2 |
-----------------------------------*
我需要通过 phone 值 (85543422) 过滤 table 并从最后一行获取用户名。 现在我有一个方法可以让你从第一行提取用户名。
//return "User1"
def getUserByPhone():String = {
val query = outgoing.filter(_.phone === "85543422").map(_.login).result.headOption
val result = Await.result(db.run(query), Duration.Inf)
if (result.value.isEmpty) return "None"
result.value.get
}
帮忙实现去掉最后一行用户名的方法。 我需要得到“User2”
您可以按 id desc 排序以获得最后一行的用户名
例
val query = outgoing.filter(_.phone === "85543422")
.sortBy(_.id.desc)
.map(_.login).result.headOption