Skip to content
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

[Feature request] Allow re-use of case class for many table names (during compile) #3044

Open
LannyRipple opened this issue Jun 13, 2024 · 0 comments

Comments

@LannyRipple
Copy link

Version: 4.8.4
Module: quill-jdbc
Database: postgresql

Desired Behavior

Allow for changing tableName enabling re-use of behaviors.

Actual behavior

// fails
class Foo(tableName: String) {
  def example(): List[PgTable] = {
    val query =
      schemaQuery[PgTable](tableName) 
        ...
  }
}

// val query = schemaQuery[PgTable]("NewTableName")...   works as expected

Above will fail to compile. Fair since tableName is not known at compile-time. I've used dynamicSchemaQuery[A](tableName) as a work-around. I'm hoping for some way to get at compile-time compilation of queries (for the perceived performance improvement since dynamic query documentation mentions a performance hit).

Motivation

Moving our system into a cluster that will not allow DocumentDB (which our system is based on). Decided on AWS RDS Postgres and Quill. Because we are moving from DocumentDB it seemed natural to use a

// quill encoder for Json <-> jsonb
case class PgTable(uuid: String, obj: Json, lastUpdated: ZonedDateTime)

to represent the layout of our many collections (now tables) and make use of Postgres's json operations. I created a basic PgRepository[A: Encoder: Decoder](tableName: String, quill: PostgresJdbcContext[Literal]) to handle most of the work. I wouldn't be adverse to using a renamed case class with same shapeless shape to handle tableName but that would also mean duplicating every service class for a new table with boilerplate def basicRepoMethod(id: String): A = { val q = query[NextTableName]... for every table.

Steps to reproduce the behavior

Happy to work up a gist or example repo if needed.

Workaround

None found (and looked at schemaMeta, etc).

With more knowledge I would make a plugin that generated the boilerplate needed for my list of tableNames against PgTable but that is beyond me.

I get that this is a niche request, a result of macro behavior, and not how one normally uses Postgres. Wanted to document the request in case it's not as difficult as I'm thinking it is.

@getquill/maintainers

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

No branches or pull requests

1 participant