Scala codegen issue for column default value and mapped type

8 views
Skip to first unread message

Satyagraha 1956

unread,
May 17, 2020, 8:15:08 AM5/17/20
to Slick / ScalaQuery
I've got a Postrgres not null varying character column which I am hoping to map to a simple type-safe wrapper type, e.g. case class CustomerId(value: String). However the database column has been set up with a default value, e.g. "000000" which I cannot change. The generated code source for the associated row case class however generates something like case class SalesRow(..., customerId: CustomerId = "000000", ...) and this clearly will generate a compile error as the base and wrapped type are not the same. The row column type is right, just not the Scala default value. So, as I specifically do not want to write any auto-conversion from String to CustomerId, what's the best way forward?

I presume the correct solution is to override the row member generation process somehow, to have the column default value wrapped in the wrapper class, but I haven't found it particularly straightforward to see how to do that. Any functioning example would be most welcome. Actually, I think this is arguably a bug or at least an oversight.

Alternatively, a way to suppress the generation of the Scala default value entirely would be acceptable, as I can easily work around that in my Scala code.

Thanks for any input!
S.

Prakash

unread,
May 17, 2020, 9:14:08 AM5/17/20
to scala...@googlegroups.com
For providing the default I would go for Scala option and while wrapping the value I will do getOrElse (default value).

Let me know if this works for you.

--

---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/52ed04c8-c88e-4ce7-8f0a-bfb16c42844a%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages