RobinBlomberg / kysely-codegen

Generate Kysely type definitions from your database.
MIT License
749 stars 67 forks source link

Add support for singularizing entities #32

Closed daniel-gato closed 1 week ago

daniel-gato commented 1 year ago

Hi,

For context: It is quite common to have tables name in their plural form to describe what the table contains. This is the approach that Ruby on Rails takes as well. Our model Car, will be stored in a "cars" table.

Would it be possible to have a "singularise-entities" to turn:

export interface Users {
  id: string;
  email: string;
}

export interface Database {
  users: Users;
}

into

export interface User {
  id: string;
  email: string;
}

export interface Database {
  users: User;
}

The same way that camelCase works?

Another reason to do that is to avoid having mixed types with reserved table names. User table name is not allowed in PG for example. In the same example, from memory, mysql won't allow table names like admin, backup, channel, action

Upvote & Fund

Fund with Polar

RobinBlomberg commented 1 year ago

This is an interesting idea. I would probably use pluralize for this.

I think, if this is implemented, we will sooner or later need a way to provide custom singularization rules as well. In that case, we might also need configuration capabilities as in #34.

acro5piano commented 2 months ago

Created a PR for this: https://github.com/RobinBlomberg/kysely-codegen/pull/162

RobinBlomberg commented 1 week ago

Should be released in kysely-codegen@0.16.0! 🚀