sqlboiler icon indicating copy to clipboard operation
sqlboiler copied to clipboard

[Feature] Table and Column Comments

Open mickeyreiss opened this issue 5 years ago • 9 comments

It would be helpful to pull comments from tables and column, and if they are present, write them as comments in the generated go code. This will help with documentation and follow the design goal: the schema is the source of truth.

If this is interesting, I can help with the mysql implementation.

mickeyreiss avatar Jul 02 '19 17:07 mickeyreiss

Would appreciate this feature very much.

aarondl avatar Jul 13 '19 01:07 aarondl

Assuming the above is acceptable, I also have plans for how to add support for PostgreSQL table comments.

sjansen avatar Oct 16 '19 23:10 sjansen

Is anyone still working on this? I'd be happy to send an updated patch in the next few days.

vladvelici avatar Jul 17 '20 11:07 vladvelici

@vladvelici I don't believe anyone has done anything with it that I'm aware of.

aarondl avatar Jul 20 '20 01:07 aarondl

I've sent a PR. There are some tests failing, seems like for mysql. I can look at that if you think I'm on the right path for postgres.

https://github.com/volatiletech/sqlboiler/pull/807

vladvelici avatar Jul 27 '20 11:07 vladvelici

I did a bit of work on adding table/struct comments too, the problem I ran in to is that the drivers.Constructor interface defines a TableNames method:

TableNames(schema string, whitelist, blacklist []string) ([]string, error)

Modifying this to also return the comments isn't possible with this function signature.

Are these interfaces considered stable? I can't add a new method to this interface without breaking users of this interface.

Otherwise I can add an optional TableInfo or TableCapabilities interface, which is a little bit uglier but maintains compatibility.

This also applies to ViewConstructor.ViewNames.

arp242 avatar Jun 21 '22 11:06 arp242

Here's a basic patch btw: https://github.com/schoolyear/sqlboiler/commit/fea0e6b76ab8b5bbc7601b92cf7c69c2d0a8c5d5

It's compatible, but has some duplication in TableNames() and Tables(), but it's not too bad and a bit hard to avoid.

I'll wait for some feedback on what patch you want to take, but as soon as that's clear I'll add a test, maybe cleanup a few things, and submit a PR.

arp242 avatar Jun 21 '22 12:06 arp242

This looks alright. Would you be able to extend this to also include column comments?

stephenafamo avatar Jun 29 '22 18:06 stephenafamo

I just saw this MR https://github.com/volatiletech/sqlboiler/pull/807

It seems that column comments are already included.

stephenafamo avatar Jun 29 '22 18:06 stephenafamo