Add support for Postgres COMMENT ON to generate JS docstring
See original GitHub issueDocs: https://www.postgresql.org/docs/current/sql-comment.html
Given this table:
create table foo (
bar text
)
comment on table foo is 'Table Foo has everything.
Even bars.'
comment on column foo.bar is 'The bar is closed.'
I would like this generated:
/**
* Table Foo has everything.
* Even bars.
*/
export interface FooEntity {
/** The bar is closed. */
bar: string
}
I believe that https://github.com/kristiandupont/kanel supports this.
Actually, looking at their examples, It would also be awesome to print comments with more information about the field (like index, default value, etc). This way when you are in your application code in your IDE, you can easily see whether a column has an index, for example.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Documentation: 15: COMMENT - PostgreSQL
COMMENT stores a comment about a database object. Only one comment string is stored for each object, so to modify a comment, issue...
Read more >PostgreSQL: Comments within SQL - TechOnTheNet
This PostgreSQL tutorial explains how to use comments within your SQL statements ... The syntax for creating a SQL comment in PostgreSQL using...
Read more >Getting Started with JSDoc 3
A quick-start to documenting JavaScript with JSDoc. ... Table of Contents. Getting started; Adding documentation comments to your code; Generating a website ...
Read more >Python help() function - DigitalOcean
Python help() function is used to get the documentation of ... the first comment string in the body of a method is used...
Read more >How to Document Stored Procedures and Functions in ...
I tried to put in one article all best practices for documenting stored ... T-SQL and PL/SQL) supports similar commenting techniques as most ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve implemented importing comments from tables, views and columns based on the following. I’ve tested across all providers and they work as intended far as I can tell. It’s quite nice as it adds the comment to the TypeScript popover.
I haven’t implemented the more verbose commenting. Most of the info can already be added using the template and hopefully this comment extraction can help with anything more expressive.
Hi, i did some research on this.
In order to support full commentaries and other information, we should get
oid
values to query other system tables.The current Postgres adapter: https://github.com/rmp135/sql-ts/blob/71c9a4ad459921e4b21a807fb7d1e90d20be1467/src/Adapters/postgres.ts#L42-L65 does not expose the
oid
, thus, it cannot provide additional information.In order to fix that, we should use the system tables instead of the system views, I’ve crafted some queries that will help us to achieve that, while maybe also adding extra functionality in case we need it.
For tables:
For columns:
It will be as simple as adding this line:
pg_catalog.col_description( pg_class.oid , pg_attribute.attnum ) as commentary,
to the SQL part of https://github.com/rmp135/sql-ts/blob/71c9a4ad459921e4b21a807fb7d1e90d20be1467/src/Adapters/postgres.ts#L67-L106 plus adding the corresponding JS/TS code.I’d do this myself, but I don’t have enough time yet, but I’ll be sure to use this library on an important commercial project in my country.
Bonus:
If we would like to get commentaries and indexes information, to likely use the handlebars file to format it like
I’ve craft this queries that should include proper
index
&foreign keys + checks
metadata along with the table information.BTW, This is such an excellent library, very well documented, crafted, non-opinionated, clean, and do perfectly what it should do.