Skip to main content
Version: 2.x

DbValue

DbValue is a sealed ADT representing every typed SQL column value the sql module handles, one case class per Scala type. Frag stores its bound parameters as IndexedSeq[DbValue], DbCodec#toDbValues produces them, and SqlDialect#typeName maps a DbValue to its DDL type string — it is the common typed currency all three share, with no JDBC imports or dependencies of its own.

VariantScala field typePostgreSQL DDLSQLite DDL
DbNull(none)NULLNULL
DbIntIntINTEGERINTEGER
DbLongLongBIGINTINTEGER
DbDoubleDoubleDOUBLE PRECISIONREAL
DbFloatFloatREALREAL
DbBooleanBooleanBOOLEANINTEGER
DbStringStringTEXTTEXT
DbBigDecimalscala.BigDecimalNUMERICTEXT
DbBytesArray[Byte]BYTEABLOB
DbShortShortSMALLINTINTEGER
DbByteByteSMALLINTINTEGER
DbCharCharCHAR(1)TEXT
DbLocalDatejava.time.LocalDateDATETEXT
DbLocalDateTimejava.time.LocalDateTimeTIMESTAMPTEXT
DbLocalTimejava.time.LocalTimeTIMETEXT
DbInstantjava.time.InstantTIMESTAMPTZTEXT
DbDurationjava.time.DurationINTERVALTEXT
DbUUIDjava.util.UUIDUUIDTEXT
DbArray(String, IndexedSeq[Any])(not in typeName)(not in typeName)

DbNull is what DbParam[Option[A]] produces for None and DbParam[Maybe[A]] produces for Maybe.absent; DbCodec matches on it to decode nullable columns, throwing IllegalStateException if a non-optional codec hits it. DbArray is the one variant with two fields (elementType, elements) instead of value, used for collection-typed columns and not currently covered by SqlDialect#typeName.

See Frag, DbCodec, and the SQL module index.