GithubHelp home page GithubHelp logo

Comments (1)

d6y avatar d6y commented on June 10, 2024

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...

  1. Add your case class.

  2. 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 ::).

  3. Change the row type to be your case class. For example, if your table is called Wide, and your case class is called WideCC then you'd end up with:

      class Wide(_tableTag: Tag) extends Table[WideCC](_tableTag, "WIDE") {
    
  4. Change the definition of * to use the Slickless mappedWith 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.

from slickless.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.