Frag

zio.blocks.sql.Frag
See theFrag companion class
object Frag

Attributes

Companion
class
Source
Frag.scala
Graph
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Frag.type

Members list

Type members

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements.

The names of the product elements.

Attributes

Inherited from:
Mirror
Source
Mirror.scala
type MirroredLabel <: String

The name of the type.

The name of the type.

Attributes

Inherited from:
Mirror
Source
Mirror.scala

Value members

Concrete methods

def keysetAfter(table: Table[_], orderCol: String, lastValue: DbValue, limit: Int): Frag

Keyset pagination fragment for a single ordering column.

Keyset pagination fragment for a single ordering column.

Produces WHERE > ? ORDER BY ASC LIMIT n as a Frag with one bound parameter (lastValue). The ordering column is validated as a SQL identifier; when a table is supplied the column must also exist in table.columns.

Single column only — composite cursors are intentionally unsupported (v2).

Attributes

Throws
IllegalArgumentException

if orderCol is not a valid identifier, not in table.columns (when a table is supplied), or if limit &lt;= 0

Source
Frag.scala
def keysetAfter(orderCol: String, lastValue: DbValue, limit: Int): Frag

Keyset pagination fragment without a table binding.

Keyset pagination fragment without a table binding.

Validates orderCol as a SQL identifier and produces WHERE > ? ORDER BY ASC LIMIT n.

Attributes

Throws
IllegalArgumentException

if orderCol is not a valid identifier or limit &lt;= 0

Source
Frag.scala
def literal(sqlStr: String): Frag

Wraps a parameter-free SQL string as a fragment.

Wraps a parameter-free SQL string as a fragment.

Attributes

Source
Frag.scala
def sequence(frags: Frag*): Frag

Concatenates multiple fragments with no separator between them. Returns Frag.empty when called with no arguments.

Concatenates multiple fragments with no separator between them. Returns Frag.empty when called with no arguments.

Attributes

Source
Frag.scala
def values[A](rows: Seq[A])(using codec: DbCodec[A]): Frag

Builds a VALUES clause for a multi-row INSERT. Renders as: (?, ?), (?, ?), ... — one tuple per row, columns within each tuple separated by ,.

Builds a VALUES clause for a multi-row INSERT. Renders as: (?, ?), (?, ?), ... — one tuple per row, columns within each tuple separated by ,.

Attributes

Throws
IllegalArgumentException

if rows is empty (empty VALUES is invalid SQL)

Source
Frag.scala

Concrete fields

val empty: Frag

An empty fragment that contributes no SQL text and no parameters.

An empty fragment that contributes no SQL text and no parameters.

Attributes

Source
Frag.scala

Extensions

Extensions

extension (frag: Frag)
def query[A](using con: DbCon, codec: DbCodec[A]): List[A]

Executes this fragment as a SELECT and returns all decoded rows.

Executes this fragment as a SELECT and returns all decoded rows.

Attributes

Source
Frag.scala
def queryChunked[A](chunkSize: Int)(using con: DbCon, codec: DbCodec[A]): Stream[Throwable, Chunk[A]]

Executes this fragment as a SELECT and returns the decoded rows as a stream of Chunks, each holding up to chunkSize rows.

Executes this fragment as a SELECT and returns the decoded rows as a stream of Chunks, each holding up to chunkSize rows.

The statement and result set are acquired lazily on the first pull and released when the stream is closed or fully drained (via Stream.fromAcquireRelease). Rows are batched by the streams layer's Reader.readN inside Stream.chunked rather than a manual List.newBuilder loop. SQL failures surface as typed errors (Left) from terminal operations such as runCollect.

Because acquisition is lazy, the stream must be consumed within the scope that provides the DbCon: leaving Transactor.connect/transact closes the captured connection, and pulling afterwards fails.

Type parameters

A

the row type, decoded through codec's column mapping

Value parameters

chunkSize

maximum number of rows per emitted Chunk; must be >= 1

codec

decoder for the expected row shape

con

the connection context providing the connection, dialect, and logger

Attributes

Returns

a lazy stream of decoded row chunks; terminal operations answer Left(error) on SQL failure

Throws
IllegalArgumentException

if chunkSize is less than 1

Example
Transactor.connect(transactor) {
 sql"SELECT id, name FROM users"
   .queryChunked[User](500)
   .runFold(0)((acc, chunk) => acc + chunk.size)
}
Source
Frag.scala
def queryLimit[A](limit: Int)(using con: DbCon, codec: DbCodec[A]): List[A]

Executes this fragment as a SELECT with a row limit.

Executes this fragment as a SELECT with a row limit.

Attributes

Source
Frag.scala
def queryOne[A](using con: DbCon, codec: DbCodec[A]): Maybe[A]

Executes this fragment as a SELECT and returns the first row, if any.

Executes this fragment as a SELECT and returns the first row, if any.

Attributes

Source
Frag.scala
def queryStream[A](using con: DbCon, codec: DbCodec[A]): Stream[Throwable, Chunk[A]]

Executes this fragment as a SELECT and returns the decoded rows as a stream of Chunks, each holding up to DefaultQueryChunkSize rows.

Executes this fragment as a SELECT and returns the decoded rows as a stream of Chunks, each holding up to DefaultQueryChunkSize rows.

Equivalent to queryChunked[A](DefaultQueryChunkSize).

Type parameters

A

the row type, decoded through codec's column mapping

Value parameters

codec

decoder for the expected row shape

con

the connection context providing the connection, dialect, and logger

Attributes

Returns

a lazy stream of decoded row chunks; see queryChunked for the acquisition lifetime and error behavior

Example
val chunks: Stream[Throwable, Chunk[User]] =
 sql"SELECT id, name FROM users".queryStream[User]
val total = chunks.runFold(0)((n, chunk) => n + chunk.size)
Source
Frag.scala
def update(using con: DbCon): Int

Executes this fragment as an INSERT/UPDATE/DELETE and returns the affected row count.

Executes this fragment as an INSERT/UPDATE/DELETE and returns the affected row count.

Attributes

Source
Frag.scala
def updateReturningKeys[A](using con: DbCon, codec: DbCodec[A]): List[A]

Executes this fragment as an INSERT and returns auto-generated keys.

Executes this fragment as an INSERT and returns auto-generated keys.

Attributes

Source
Frag.scala