Skip to content

SimpleTable with Record, w/o marker class #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

bishabosha
Copy link

@bishabosha bishabosha commented May 5, 2025

compared to the initial PR #81, this trades in dropping the marker class for a more complex implementation where the type of the Expression has to be re-computed on each .select, .insert etc, and passed as a type parameter to the record class. This also relies upon transparent inline and macros to compute the types (IntelliJ issue maybe?)

However as far as I know IntelliJ doesn't support match types either so probably a moot point

import scalasql.dialects.H2Dialect.*
import scalasql.namedtuples.*
import scalasql.*

case class Person(name: String, age: Int)
object Person extends SimpleTable[Person]()

case class City(name: String, population: Int, mayor: Person)
object City extends SimpleTable[City]()

@main def foo =
  City.select.filter(_.name === "foo")
  City.insert.values(City("foo", 42, Person("bar", 23)))
  City.insert.columns(_.name := "foo")
  City.insert.batched(_.name, _.population, _.mayor.name)(("foo", 42, "bar"), ("baz", 23, "qux"))

inside an expression, you have the type SimpleTable.Record[City, (name : Expr[String], population : Expr[Int], mayor : SimpleTable.Record[Person, (name : Expr[String], age : Expr[Int])])], inferred by metals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant