kriasoft / knex-types

Generate TypeScript definitions (types) from a PostgreSQL database schema.
MIT License
63 stars 21 forks source link

add support for comments #6

Open bhenderson opened 3 years ago

bhenderson commented 3 years ago

We recently started putting comments into our database and we thought it would be awesome if this lib could add the comments as documentation in the output. This might be specific to postgres so I'm not sure how that would work. Potentially this lib could just offer a hook so we could add our own documentation before the typescript definition.

We add comments like this:

-- table
comment on table my_table is 'This is my table';

-- column
comment on column my_column.id is 'PK of my_table';

actually, the more I think about it, general hooks is probably the way to go. This would also solve my problems for #5 and #4.

great library by the way, it has been super helpful!

koistya commented 3 years ago

Good idea! Generating JSDoc comments from the actual database schema would be nice. At least for database tables. It can be done by integrating the following SQL query into the lib:

SELECT description FROM pg_description
  JOIN pg_class ON pg_description.objoid = pg_class.oid
  JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid
WHERE relname = '<table name>' AND nspname='<schema name>'