sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.58k stars 812 forks source link

Expose Comment Metadata to plugin Types. #3589

Open Smithx10 opened 2 months ago

Smithx10 commented 2 months ago

What do you want to change?

Currently, I am in the process of replacing Ent with SQLC. Our workflow involves writing our database schema, generate functions that map to sql queries, which sqlc accomplishes wonderfully, and then generate .proto messages for use in our gRPC APi. Typically we import them to our request_response.proto. In Ent this was done via https://github.com/ent/contrib/tree/master/entproto

Comment annotations in line with the schema will allow plugin authors apply logic to for example:

The functions for the compiler to collect the comments from the Schema files looks like it could be altered to accomplish this. I don't believe this will have any negative effects to the project.

What database engines need to be changed?

No response

What programming language backends need to be changed?

No response

Smithx10 commented 2 months ago

Not sure if we will be able to easily get Column level comments from the parser. https://github.com/pganalyze/libpg_query/issues/103 Looks like they added comments, but no one has caught up to it.

Smithx10 commented 2 months ago

I've created a quick first pass PoC to generate messages from sqlc:

https://github.com/Smithx10/sqlc-gen-proto

Smithx10 commented 2 months ago

Would like to have https://github.com/sqlc-dev/sqlc/issues/3596 , When generating .proto files the Primary key should always be field 0.