All Downloads are FREE. Search and download functionalities are using the official Maven repository.

typo.dsl.SortOrder.scala Maven / Gradle / Ivy

The newest version!
package typo.dsl

import zio.Chunk
import zio.jdbc.*

sealed trait SortOrderNoHkt[NT] {
  val expr: SqlExpr.SqlExprNoHkt[NT]
  val ascending: Boolean
  val nullsFirst: Boolean

  def withNullsFirst: SortOrderNoHkt[NT]

  final def render(ctx: RenderCtx): SqlFragment = {
    Chunk(
      expr.render(ctx),
      if (ascending) sql"ASC" else sql"DESC",
      if (nullsFirst) sql"NULLS FIRST" else SqlFragment.empty
    ).mkFragment(" ")
  }
}

// sort by a field
final case class SortOrder[T, N[_]](expr: SqlExpr[T, N], ascending: Boolean, nullsFirst: Boolean)(implicit val ordering: Ordering[T], val nullability: Nullability[N]) extends SortOrderNoHkt[N[T]] {
  def withNullsFirst: SortOrder[T, N] = copy(nullsFirst = true)(ordering, nullability)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy