Skip to content

Support for extensible records #18

Description

@rfuerst87

I've been playing around with slickless for the past few days. I'm particularly interested in getting extensible records to work with slick. A "record projection" would be a nice feature IMHO. Either by providing a RecordShape or by a MappedProjection.

class Users(tag: Tag) extends Table[Long :: String :: HNil](tag, "users") {
  def id    = column[Long]( "id", O.PrimaryKey, O.AutoInc )
  def email = column[String]("email")

  def * = ('id ->> id) :: ('email ->> email) :: HNil    // support by RecordShape
  // or
  def * = (id :: email :: HNil).mappedWithRecord('id :: 'email :: HNil)  // support by MappedProjection
}

As I just started my journey with shapeless, I could not get any of these two approaches to work. The closest I could come up with is a non working MappedProjection:

def mappedWithRecord[R <: HList : ClassTag, U <: HList, K <: HList](keys: K)
  (implicit
    shape: Shape[_ <: FlatShapeLevel, T, U, _]) =
  new MappedProjection[R, U](
    shape.toNode(hlist),
    MappedScalaType.Mapper(
      ((f: HList) => f.zipWithKeys(keys)).asInstanceOf[Any => Any], // compiler error: could not find implicit value for parameter withKeys: shapeless.ops.hlist.ZipWithKeys[K,shapeless.HList]

      ((g: HList) => ???).asInstanceOf[Any => Any],
      None
    ),
    implicitly[ClassTag[R]]
  )
}

So basically my two questions are:

  1. Would it even be possible to provide a RecordShape? Unfortunately I could not even figure out where to start...
  2. Why can't the compile find the implicit parameter withKeys in the code above? What am I missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions