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

harness.sql.query.Delete.scala Maven / Gradle / Ivy

There is a newer version: 5.1.3
Show newest version
package harness.sql.query

import harness.sql.*
import harness.sql.typeclass.*

object Delete {

  def from[T[_[_]] <: Table](name: String)(implicit ti: TableSchema[T]): Q1[T[AppliedCol]] =
    Q1(
      ti.functorK.mapK(ti.columns)(AppliedCol.withVarName(name)),
      fr"DELETE FROM ${ti.referenceName} $name",
    )

  final class Q1[T] private[Delete] (
      t: T,
      fragment: Fragment,
  ) {

    // TODO (KR) : Support joins

    def where(f: T => QueryBool): Delete.Query[T] =
      Delete.Query(
        t,
        fr"$fragment WHERE ${f(t)}",
      )

  }

  final class Query[T] private[Delete] (
      t: T,
      private[query] val fragment: Fragment,
  ) {

    def returning[T2](f: T => Returning[T2]): QueryR[T2] = {
      val ret = f(t)
      QueryR(
        fr"$fragment RETURNING $ret",
        ret.decoder,
      )
    }

  }

  final class QueryR[O] private[Delete] (
      private[query] val fragment: Fragment,
      private[query] val decoder: QueryDecoderMany[O],
  )

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy