Skip to content

Conversation

QuentinN42
Copy link

Fixes #88

To fix this issue, here is my proposition:

 class Author(pydantic.BaseModel): + model_config = pydantic.ConfigDict( + validate_by_alias=True, + validate_by_name=True, + ) id: int + class_: str = pydantic.Field( + alias="class", + ) - class: str
  1. I'm replacing the class reserved keyword by class_.
  2. I add validate_by_name to allow us to define the class using Author(class_=...).
  3. I add validate_by_alias to allow JSON serde.

Changes overview

  1. I've created a new file : internal/poet/reserved.go to append _ to reserved names.
  2. I've modified internal/gen.go::pydanticNode to add model_config = pydantic.ConfigDict
  3. I've modified internal/gen.go::fieldNode:
  • If not reserved keyword, code unchanged.
  • Else if using pydantic, add the _ and add pydantic.Field(...)
  • Else if dataclasses, only add the _
  1. Added tests

Questions / possible issues

  1. To run the tests, I just clonned the repo and ran make test is it correct ?
  2. I had to update all comment from sqlc v1.28.0 to sqlc v1.29.0 is this intended ?
  3. The wasm sha256 changed, should I commit that ?
  4. In internal/poet/reserved.go I hardcoded reservedKeywords we should double check it and check if we want to keep it like that.
  5. Do you want me to add more tests ?
…n reserved keywords Signed-off-by: QuentinN42 <quentin@lieumont.fr>
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
…figDict Signed-off-by: QuentinN42 <quentin@lieumont.fr>
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant