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

Add code generation support for insertable / updatable Records and POJOs #16599

Open
10 tasks
lukaseder opened this issue Apr 26, 2024 · 0 comments
Open
10 tasks

Comments

@lukaseder
Copy link
Member

There have been some interesting discussions in a previous issue:

A common desire, especially in the kotlin ecosystem, is to have a more accurate reflection of nullability in some types of columns, which are nullable on insert, but non-nullable on read. This includes identity columns, for example. Numerous examples of users requesting changes here are:

jOOQ cannot accomodate these wishes out of the box, as it must be possible to create a POJO / Record containing a null value for an identity. It will become non-null only after storing the value (if it is fetched back from the server).

A thorough solution would be to offer multiple representations of the same record for multiple purposes:

  • A representation for INSERT (obtained when calling ctx.newRecord(TABLE))
    • Defaulted columns, including identities, are always nullable (irrespective of NOT NULL constraints)
    • Non-insertable columns are absent
  • A representation for UPDATE (obtained when fetching ctx.selectFrom(TABLE) or ctx.insertInto(TABLE).returning(), etc.)
    • NOT NULL columns are always non-nullable
    • Non-updatable columns are readonly

Other representations as suggested in #14566 won't be added for now:

  • A readonly representation
  • An all-nullable representation

This feature interacts with the suggested concept of insertable and updatable columns:

Tasks

  • Implement the code generation feature
    • It must be opt-in, default is the current behaviour
  • Implement new runtime API. There's going to be a need for new TableRecord style marker interfaces, which offer the appropriate generics to allow for the appropriate change of behaviour with ctx.newRecord(), etc.

Caveats

  • Current UpdatableRecord API can't model the state transition from an InsertableRecord to an UpdatableRecord: record.store() and record.insert() returns only the update count, not the new representation.

This issue needs a lot more thought before we can start implementing it

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

No branches or pull requests

1 participant