KuceraMartin / tyqu

Type-safe Queries
Apache License 2.0
50 stars 3 forks source link

recursive types on relationships #13

Closed KuceraMartin closed 1 year ago

KuceraMartin commented 1 year ago

solutions:

KuceraMartin commented 1 year ago

search for "recursive" in the macro doc

KuceraMartin commented 1 year ago

https://github.com/mbovel/scala-sql/tree/main/examples/21-recursive-refinement

KuceraMartin commented 1 year ago

another solution might be that the querybuilder generates implicit "capabilties" to join with other tables, which provide extension methods that do the joins? update: the problem here is that these extension methods would have to be generated since their names are derived from the schema definition

KuceraMartin commented 1 year ago

Nicolas was worried that there might be some problems with recursive schema definitions but that seems to be okay (see https://github.com/mbovel/scala-sql/blob/main/examples/13-relation.sc)

edit: referencing objects works, but for properties it's a bit more tricky: recursive references seem to work when you declare the types, but in reality you end up with nulls!

KuceraMartin commented 1 year ago

using lazy vals: https://github.com/mbovel/scala-sql/blob/main/examples/23-hardcode-scope-with-recursion.sc

KuceraMartin commented 1 year ago

For generating files, we could take inspiration from Slick: https://scala-slick.org/doc/3.4.0-M1/code-generation.html which uses sbt: https://www.scala-sbt.org/1.x/docs/Howto-Generating-Files.html Maybe we could make some sbt plugin to reduce the build.sbt boilerplate for the users?

KuceraMartin commented 1 year ago
KuceraMartin commented 1 year ago

add one paragraph about code generation: should it always be done through macros? and if not, then how?

KuceraMartin commented 1 year ago

Nicolas suggested something similar to Alex:

class PersonScope:
  def home[T](using x: F[T])(using T =:= House): x.type

where x would be given by House automatically using derives (TODO: try to understand this)

Guillaume suggested generating code and giving back to user through error messages -> IDE would display these and the could could be emplaced by one click.

KuceraMartin commented 1 year ago

from discussion with Viktor: could we somehow use this?

class MyList:
  val value: Any = ???
  val next: this.type = ???

type IntList = MyList { val value: Int }

(??? : IntList).next.next.value : Int