I want to know slickless has code genertaor like Slick
Closed this issue · 1 comments
Hello @hongBry
Short answer
Slickless does not have a code generation.
Slightly longer answer
Slick's own code generator will use Slick's own HList implementation for tables with > 22 columns. However, it won't do a case class mapping automatically (only because no-one has written the code yet).
If you write your own case class you should be able to edit the generated code and modify the def *
implementation. You'll need to make it look like:
def * = (field1 :: field2...etc :: HNil).mapTo[YourCaseClassHere]
Make sure you change the table defintion to extend Table[YourCaseClassHere]
.
You can then work (insert, query, etc) in terms of the case class.
A long answer
If you really want to use shapeless HLists for some reason, I'm reasonably sure you can modify the generated code to use shapeless and Slickless.
Here's how. In the generated table code...
-
Add your case class.
-
Replace...
import slick.collection.heterogeneous._ import slick.collection.heterogeneous.syntax._
with:
import shapeless._ import slickless._ type HCons[H,T <: HList] = H :: T
(As an alternative to the type alias, search and replace
HCons
in the generated code with the shapeless::
). -
Change the row type to be your case class. For example, if your table is called
Wide
, and your case class is calledWideCC
then you'd end up with:class Wide(_tableTag: Tag) extends Table[WideCC](_tableTag, "WIDE") {
-
Change the definition of
*
to use the SlicklessmappedWith
method. For example:def * = (field1 :: field2 .... :: HNil).mappedWith(Generic[WideCC])
With those changes in place, you can query your wide tables and get back case classes.