Skip to content

Commit

Permalink
Minor refactoring in pagination and fix parantheses in query
Browse files Browse the repository at this point in the history
  • Loading branch information
manojlds committed Jan 4, 2018
1 parent 9e04d4a commit 1c0a385
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import scala.concurrent.{ExecutionContext, Future}

case class PaginatedFilter(
id: Option[UUID],
first: Int,
first: Option[Int],
after: Option[DateTime],
last: Int,
last: Option[Int],
before: Option[DateTime]
)
) {
def take = (last orElse first).filter(_ <= 10).getOrElse(10) + 1
}

class SchemaDao(val db: SqlDatabase)(implicit val ec: ExecutionContext) {
import db.ctx._
Expand All @@ -31,15 +33,15 @@ class SchemaDao(val db: SqlDatabase)(implicit val ec: ExecutionContext) {

def findFirstVersions(filter: PaginatedFilter) = {
val query = quote {
applyCursors(lift(filter)).sortBy(_.createdOn)(Ord.descNullsLast).take(lift(filter.first))
applyCursors(lift(filter)).sortBy(_.createdOn)(Ord.descNullsLast).take(lift(filter.take))
}

run(query)
}

def findLastVersions(filter: PaginatedFilter) = {
val query = quote {
applyCursors(lift(filter)).sortBy(_.createdOn)(Ord.ascNullsLast).take(lift(filter.last))
applyCursors(lift(filter)).sortBy(_.createdOn)(Ord.ascNullsLast).take(lift(filter.take))
}

run(query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class GraphQLService(
val filter =
PaginatedFilter(
Some(id),
first.getOrElse(10) + 1,
first,
after.map(_.toDateTime),
last.getOrElse(10) + 1,
last,
before.map(_.toDateTime)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ trait Quotes { this: PostgresAsyncContext[_] =>
}

implicit class OptDateTimeQuotes(l: Option[DateTime]) {
def >(r: DateTime) = quote(infix"($l::timestamptz is null) or $l > $r".as[Boolean])
def <(r: DateTime) = quote(infix"($l::timestamptz is null) or $l < $r".as[Boolean])
def >(r: DateTime) = quote(infix"($l::timestamptz is null or $l > $r)".as[Boolean])
def <(r: DateTime) = quote(infix"($l::timestamptz is null or $l < $r)".as[Boolean])
}
}

Expand Down

0 comments on commit 1c0a385

Please sign in to comment.