Skip to content
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

Retrieve comments from database tables, override, and output #21

Merged
merged 1 commit into from
Nov 15, 2024

Conversation

Envek
Copy link
Contributor

@Envek Envek commented Nov 14, 2024

Output database column comments as TS comments before fields.

Disabled by default. Enable it with:

Typelizer.configure do |c|
  c.comments = true
end

Given that ActiveRecord migration declares table column comment:

create_table :users do |t|
  t.string :login, null: false, comment: "User public @handle"
end

Output it as a comment before field typings in generated interface:

type AmsUserAuthor = {
  id: number;
  // Author login handle
  username: string | null;
  avatar: unknown;
}

typelize directive accepts comment option that overrides comment from the database or suppresses it if false is given.

typelize username: [:string, comment: "Username is username, that's it"]

Main use cases:

  1. There is no comment in the database, no typelize directive: no comment
  2. There is a comment in the database, no typelize directive: database comment used
  3. There is no comment in the database, typelize directive has comment option: directive comment used
  4. There is a comment in the database, typelize directive has comment option: directive comment used
  5. There is a comment in the database, typelize directive has comment: false: no comment

NB: I couldn't make test for this as SQLite doesn't support comments for database objects.

@skryukov skryukov merged commit d5ead3d into skryukov:main Nov 15, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants