You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's inconvenient to derive a DbCodec when two fields of the same type require different codecs, because the imports conflict. One approach to fix this would be implementing a DbCodecOverride and SqlArrayCodecOverride annotation, like:
/** This annotation allows the user to explicitly select the DbCodec used on a field. * It's useful if you have two fields of the same type that require different codecs. For example, * assume we have two LongCodecs: * {{{ * val codecA: DbCodec[Long] = ??? * val codecB: DbCodec[Long] = ??? * * case class MyUser(a: Long, b: Long) derives DbCodec * }}} * * And `codecA` should be used for field `a`, and `codecB` for field b. * The normal approach of importing both codecs won't work, since they have the same type and will conflict. * Instead, we can do * * {{{ * case class MyUser( * @DbCodecOverride(codecA) a: Long, * @DbCodecOverride(codecB) b: Long * ) derives DbCodec * }}} * * */classDbCodecOverride[A](valcodec:DbCodec[A]) extendsStaticAnnotation
This looks like a workable solution. I personally would prefer a more succinct (and less dramatic) name for the annotation. Something like @DbColumn(codecA) maybe. "Override" suggests that you (the library user) are doing something really weird/crazy/out-of-the-ordinary/dangerous. But the annotation is merely for the purposes of selecting a particular codec when several are available.
It's inconvenient to derive a DbCodec when two fields of the same type require different codecs, because the imports conflict. One approach to fix this would be implementing a
DbCodecOverride
andSqlArrayCodecOverride
annotation, like:#36 (comment)
The text was updated successfully, but these errors were encountered: