Using camel case with kanel-kysely
sebastian-schuler opened this issue · 3 comments
sebastian-schuler commented
I want to use Kyselys CamelCasePlugin, how can I generate the types with Kanel accordingly? Is there some sort of workaround in place?
kristiandupont commented
I don't have any experience with that plugin but you can solve almost anything by writing a pre-render hook.
alecmev commented
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 commented
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! :-)