【问题标题】:Use Long value as drop and take in a quill query使用 Long 值作为 drop 并接受 quill 查询
【发布时间】:2020-11-22 12:09:37
【问题描述】:

我有一个简单的端点,它从数据库中返回一些记录。端点支持分页。 因此,我有以下 quill-query

query[HandbookModule].drop(lift(offset)).take(lift(limit))

我希望分页支持 int64/Long 值,但据我所知,quill 仅支持 Int 值。

我只是错过了如何做到这一点,还是用 quill 无法做到这一点。

【问题讨论】:

    标签: database scala pagination


    【解决方案1】:

    32 位整数最大值远远超过 20 亿。你确定你的数据库真的会有那个卷吗?也许将那个长缩小到 int 就可以了?

    无论如何,您可以在一定程度上使用中缀 dsl 自定义 quill:

    def find(..., take: Long, ...) = {
        implicit class LongTake[T](q: Query[T]) {
          def lTake(l: Long) = quote(infix"$q take $l".as[Query[T]])
        }
        query[HandbookModule].drop(lift(offset)).lTake(lift(limit))
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-21
      • 2021-11-14
      • 2011-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 2017-06-29
      相关资源
      最近更新 更多