-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include postgres comments in output #392
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #392 +/- ##
==========================================
+ Coverage 90.49% 90.56% +0.06%
==========================================
Files 125 125
Lines 7458 7460 +2
==========================================
+ Hits 6749 6756 +7
+ Misses 550 545 -5
Partials 159 159
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Nice. Didn't know postgres has comment support like mysql. jet/tests/mysql/generator_test.go Line 215 in 6a0798e
and jet/tests/mysql/generator_test.go Line 235 in 6a0798e
Note that test data files are in separate repo. |
WIP: Tests still missing. Will add them asap |
There's also support for individual table column comments. You could in theory add a // comment to each generated field if you like. There's probably a much better way of doing this, but I wanted something that'll give you a single query for this. here's the reference: https://www.postgresonline.com/journal/archives/215-Querying-table,-view,-column-and-function-descriptions.html with table_comments as (
SELECT n.nspname AS sname, c.relname As tname,
CASE WHEN c.relkind = 'v' THEN 'view' ELSE 'table' END As type,
d.description as table_comment
FROM pg_class As c
INNER JOIN pg_attribute As a ON c.oid = a.attrelid
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace
LEFT JOIN pg_description As d ON (d.objoid = c.oid AND d.objsubid = 0) --
WHERE c.relkind IN('r', 'v') -- AND d.description > ''
ORDER BY n.nspname, c.relname
), column_comments as (
SELECT n.nspname as sname, c.relname as tname , a.attname As column_name, d.description as column_description
FROM pg_class As c
INNER JOIN pg_attribute As a ON c.oid = a.attrelid
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace
LEFT JOIN pg_description As d ON (d.objoid = c.oid AND d.objsubid = a.attnum)
WHERE c.relkind IN('r', 'v') and d.description <> '' -- AND n.nspname = 'SCHEMA' AND c.relname = 'TABLENAME'
ORDER BY d.description, n.nspname, c.relname, a.attname
) select distinct t.sname, t.tname, t.table_comment, c.column_name, c.column_description from table_comments as t full outer join column_comments as c on t.tname = c.tname and t.sname = t.sname
where (t.table_comment <> '' or c.column_description <> ''); Should return the comments for both tables and columns. |
Thanks for the info :) |
Waiting for go-jet/jet-test-data#6 |
Thanks, looks good. 👍 |
#391
Please double check as I'm not an expert in postgres internals!