sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

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

Open PaulSonOfLars opened this issue 1 year ago • 1 comments

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 avatar Jun 07 '24 17:06 PaulSonOfLars

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

ChocoChipset avatar Oct 10 '24 12:10 ChocoChipset

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';

ChocoChipset avatar Dec 03 '24 13:12 ChocoChipset

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 avatar Dec 26 '24 22:12 oxisto