Skip to main content

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])TEXT[]TEXT

DbNull is what DbParam[Option[A]] produces for None and DbParam[Maybe[A]] produces for Maybe.absent; DbNull appears only on the write side: decoding never sees a DbValue, because codecs read from a result reader and detect NULL themselves. A non-optional codec does not fail on NULL either, except for BigDecimal and a derived Char: Int reads 0 and String reads null. DbArray is the one variant with two fields (elementType, elements) instead of value, used for collection-typed columns and mapped by SqlDialect#typeName to TEXT[] on PostgreSQL and TEXT on SQLite.

See Frag, DbCodec, and the SQL module index.