Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow for passing comments through the table schema to the generated Go Struct #3430

Open
PaulSonOfLars opened this issue Jun 7, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@PaulSonOfLars
Copy link

What do you want to change?

Currently, generating a table from the basic SQL will strip the field comments completely:

CREATE TABLE test (
  id text PRIMARY KEY,
-- Some helpful comment to pass on to the go code
  some_field text NOT NULL
)

It would be great if we could write comments in our table description, and have that comment show up in our go code as it gets run. Some fields need more than just a name, and having these would be a really helpful way of reading the code. Most people will read the go struct, not go hunt for the SQL file with the comments themselves.

Happy to open a PR for it if theres interest :)

What database engines need to be changed?

No response

What programming language backends need to be changed?

Go

@PaulSonOfLars PaulSonOfLars added enhancement New feature or request triage New issues that hasn't been reviewed labels Jun 7, 2024
@kyleconroy kyleconroy removed the triage New issues that hasn't been reviewed label Aug 5, 2024
@ChocoChipset
Copy link

Migrated recently to sqlc. I'm missing the comments in my old classes. :(

@ChocoChipset
Copy link

For anyone interested: this can be achieved by using comment on

CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);
comment on table authors is 'contains authors in the library';
comment on column authors.name is 'name of the author starting with first name';

@oxisto
Copy link

oxisto commented Dec 26, 2024

For anyone interested: this can be achieved by using comment on

CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);
comment on table authors is 'contains authors in the library';
comment on column authors.name is 'name of the author starting with first name';

Unfortunately this does not work for sqlite :(

oxisto added a commit to oxisto/sqlc that referenced this issue Dec 27, 2024
This is a partial solution for sqlc-dev#3430 for sqlite, which may or may not be adaptable for other engines. It basically looks for single-line comments before the CREATE command and in-between column definitions.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants