DbCodec

zio.blocks.sql.DbCodec
See theDbCodec companion trait
object DbCodec

Attributes

Companion
trait
Source
DbCodec.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
DbCodec.type

Members list

Value members

Concrete methods

def apply[A](implicit codec: DbCodec[A]): DbCodec[A]

Attributes

Source
DbCodec.scala
inline def builder[A]: DerivationBuilder[DbCodec, A]

Returns a derivation builder for DbCodec so callers can attach precise field/type overrides before deriving the final codec.

Returns a derivation builder for DbCodec so callers can attach precise field/type overrides before deriving the final codec.

Attributes

Source
DbCodec.scala
inline def derivedWith[A](configure: DerivationBuilder[DbCodec, A] => DerivationBuilder[DbCodec, A]): DbCodec[A]

Derives a DbCodec after applying caller-supplied derivation-builder overrides such as field-level custom codecs.

Derives a DbCodec after applying caller-supplied derivation-builder overrides such as field-level custom codecs.

Attributes

Source
DbCodec.scala
def jsonb[A](using jsonCodec: JsonCodec[A]): DbCodec[A]

Attributes

Source
DbCodec.scala
def jsonb[A](encode: A => String, decode: String => A): DbCodec[A]

Attributes

Source
DbCodec.scala
def jsonbOption[A](using jsonCodec: JsonCodec[A]): DbCodec[Option[A]]

Attributes

Source
DbCodec.scala
def jsonbOption[A](encode: A => String, decode: String => A): DbCodec[Option[A]]

Attributes

Source
DbCodec.scala

Givens

Givens

given bigDecimalCodec: DbCodec[BigDecimal]

Attributes

Source
DbCodec.scala
given booleanCodec: DbCodec[Boolean]

Attributes

Source
DbCodec.scala
given byteCodec: DbCodec[Byte]

Attributes

Source
DbCodec.scala
given dbCodecFromAs: [A, B] => (As[A, B], DbCodec[A]) => DbCodec[B]

Auto-derives a DbCodec[B] from DbCodec[A] and As[A, B].

Auto-derives a DbCodec[B] from DbCodec[A] and As[A, B].

This enables Scala 3 opaque types and ZIO Prelude Newtype/Subtype values to receive a DbCodec for free when their underlying type already has one:

opaque type ProductId = String
// provide As[String, ProductId] in the ProductId companion object
// DbCodec[ProductId] is then resolved automatically — no explicit given needed

This given is lower priority than any explicit given DbCodec[B] or derived because it lives in the companion object at the same level as primitive codecs but is polymorphic (two type parameters), making it less specific than any monomorphic given for a concrete type B.

Use DbCodec[A].transform for types that do not have an As instance.

Attributes

Source
DbCodec.scala
inline given derived: [A] => DbCodec[A]

Derives a DbCodec[A] using the default column name mapper. Self-contained: derives Schema[A] internally, so no Schema needs to be in scope. Enables the Scala 3 derives clause: case class User(...) derives DbCodec

Derives a DbCodec[A] using the default column name mapper. Self-contained: derives Schema[A] internally, so no Schema needs to be in scope. Enables the Scala 3 derives clause: case class User(...) derives DbCodec

Attributes

Source
DbCodec.scala
given doubleCodec: DbCodec[Double]

Attributes

Source
DbCodec.scala
given floatCodec: DbCodec[Float]

Attributes

Source
DbCodec.scala

Attributes

Source
DbCodec.scala
given intCodec: DbCodec[Int]

Attributes

Source
DbCodec.scala
given longCodec: DbCodec[Long]

Attributes

Source
DbCodec.scala
given maybeCodec: [A] => DbCodec[A] => DbCodec[Maybe[A]]

Attributes

Source
DbCodec.scala
given optionCodec: [A] => DbCodec[A] => DbCodec[Option[A]]

Attributes

Source
DbCodec.scala
given shortCodec: DbCodec[Short]

Attributes

Source
DbCodec.scala
given stringCodec: DbCodec[String]

Attributes

Source
DbCodec.scala
inline given tupleCodec: [T <: Tuple] => DbCodec[T]

Attributes

Source
DbCodec.scala

Inherited givens

inline given derivedOpaque: [A] => DbCodec[A]

Auto-derives a DbCodec[A] for Scala 3 opaque types by reusing the codec of the underlying type. The opaque type companion must expose a public apply method from the underlying type to the opaque type, so decode uses the same validation/wrapping path as user code.

Auto-derives a DbCodec[A] for Scala 3 opaque types by reusing the codec of the underlying type. The opaque type companion must expose a public apply method from the underlying type to the opaque type, so decode uses the same validation/wrapping path as user code.

For encoding, either define the opaque type as a subtype of the underlying type:

opaque type ProductId &lt;: String = String
object ProductId { def apply(value: String): ProductId = value }

or provide a public unwrap method:

opaque type ProductId = String
object ProductId {
 def apply(value: String): ProductId = value
 def unwrap(value: ProductId): String = value
}

This given lives in a super-trait so it has lower priority than derived (requires Schema) and dbCodecFromAs (requires As), both of which are defined in object DbCodec itself.

Attributes

Inherited from:
DbCodecOpaquePriority (hidden)
Source
DbCodec.scala