Reputation: 20080
Slick codegen generates an handy Tables.scala with all the classes for the rows and the tables. We like this approach because we can use relational design and exploit the full power of the SQL dialect we choose.
However, we are writing a lot of boiler plate code to convert from our REST API Model / Domain API Model to slick XYZ row for the following reasons:
Can we automatize the conversion so we do not have to write explicitely every time two conversion functions, from domain model to slick case classes and viceversa. In particular:
How do write a generic function that provides an implicit conversion between two equivalent case classes with the same HLIST representation?
How do we write a generic implicit conversion between two case classes with a different HLIST representation, provided a set of implicit conversions in scope for the different members (java.sql.Timestamp -> java.time.ZonedDateTime)
How do we write a function to convert between two case classes where the output one has a Repr = HList1 :: HList2 and the first one has a Repr = HList2 (i.e. how do we prepend / append to HList2 the parameters extracted from the request?)
Upvotes: 2
Views: 260
Reputation: 1575
There are a handful of libraries that do this which you could use or read the source to learn from. For example https://index.scala-lang.org/davegurnell/bulletin/bulletin/0.7.0
Upvotes: 2