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

Using camel case with kanel-kysely #547

Closed
sebastian-schuler opened this issue Mar 25, 2024 · 3 comments · Fixed by #562
Closed

Using camel case with kanel-kysely #547

sebastian-schuler opened this issue Mar 25, 2024 · 3 comments · Fixed by #562

Comments

@sebastian-schuler
Copy link

I want to use Kyselys CamelCasePlugin, how can I generate the types with Kanel accordingly? Is there some sort of workaround in place?

@kristiandupont
Copy link
Owner

I don't have any experience with that plugin but you can solve almost anything by writing a pre-render hook.

@alecmev
Copy link
Contributor

alecmev commented May 28, 2024

For future readers:

import { camelCase } from 'change-case';
import kanel, { type Output } from 'kanel';
import kanelKysely from 'kanel-kysely';

const camelCaseHook = (output: Output): Output =>
  Object.fromEntries(
    Object.entries(output).map(([path, fileContents]) => [
      path,
      {
        ...fileContents,
        declarations: fileContents.declarations.map((declaration) =>
          declaration.declarationType === 'interface' ?
            {
              ...declaration,
              properties: declaration.properties.map((property) => ({
                ...property,
                name: camelCase(property.name),
              })),
            }
          : declaration,
        ),
      },
    ]),
  );

await kanel.processDatabase({
  // ...
  preRenderHooks: [kanelKysely.makeKyselyHook(), camelCaseHook],
});

Maybe this hook could come bundled with kanel-kysely?

@kristiandupont
Copy link
Owner

I'd be happy to if this is something that is common. The thing is that I don't really use Kysely myself, so I just provided what appeared to be what is expected. PR's from people with proper knowledge are very welcomed! :-)

alecmev added a commit to alecmev/kanel that referenced this issue May 28, 2024
alecmev added a commit to alecmev/kanel that referenced this issue Jun 10, 2024
kristiandupont pushed a commit that referenced this issue Jun 11, 2024
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 a pull request may close this issue.

3 participants