Skip to content

Add SimpleTable construct based on Named Tuples #81

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 16 commits into
base: main
Choose a base branch
from

Conversation

bishabosha
Copy link

@bishabosha bishabosha commented May 4, 2025

This provides a SimpleTable class that extends Table, but allows to define the case class without a higher-kinded type parameter.

In turn, expressions are based on a Record class, that is structurally typed, that can convert easily back to the original case class.

In this design, there are no macros, and no transparent inline. To simplify the type gymnastics it is required for the case class to extend SimpleTable.Source. Other designs are possible e.g. #82

package scalasql.example

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

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

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

@main def foo =
  City.select.filter(_.name === "foo").map(_.mayor)
  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 the expressions you have the type Record[City, Expr], with structural fields

@bishabosha bishabosha force-pushed the feature/table-named-tuples branch from 1501969 to 496dc23 Compare May 5, 2025 16:30
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