Supporting camelcase
Closed this issue · 9 comments
Thanks for this library!
Would it be possible to support camelcase, like the kysely-codegen library?
The final DB
type that gets generated still has all the keys in snake case, so it would be awesome to be able to configure that as camel case as well.
Let me make sure I understand you correctly. You mean that your Prisma schema generates a database that uses snake case names, but you want to generate types for Kysely that use camel case and depend on the camel case plugin?
If that's the case it should be pretty straightforward to implement.
I'd be interested to hear what your use case is for this though. Is there something holding you back from renaming the fields in your schema so they use camel case?
Hey @aniravi24! I've made a first attempt at addressing this. Could you try using snapshot version 0.0.0-snapshot-20230323111034
and setting camelCase = true
in the generator config:
generator kysely {
provider = "prisma-kysely"
// ...
camelCase = true
}
And of course use the camel case plugin when you instantiate the Kysely instance.
Let me know if this works for you 😄
Let me make sure I understand you correctly. You mean that your Prisma schema generates a database that uses snake case names, but you want to generate types for Kysely that use camel case and depend on the camel case plugin?
If that's the case it should be pretty straightforward to implement.
I'd be interested to hear what your use case is for this though. Is there something holding you back from renaming the fields in your schema so they use camel case?
Not quite, my Prisma schema does use camel case (underlying DB is using snake case but I map all tables and fields to camel case), and most of the types are also in camel case in the output. The issue is that the final DB
type export that the library is generating has all the table names in snake case instead of camel case.
Ah gotcha. Try using the snapshot. If I understand you correctly it should solve this issue.
@valtyr just to be more concrete with an example, my prisma model looks like this
model TaxAuthority {
id String @id @default(uuid()) @db.Uuid
percent Float
insertedAt DateTime @default(now()) @map("inserted_at") @db.Timestamptz(6)
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(6)
description String
@@map("tax_authority")
}
TS type for model
export type TaxAuthority = {
id: string;
percent: number;
insertedAt: Generated<Timestamp>;
updatedAt: Generated<Timestamp>;
description: string;
};
DB type export (notice how it's snake instead of camel case)
export type DB = {
tax_authority: TaxAuthority;
};
snapshot works! It outputs in camelcase now.
export interface DB {
taxAuthority: TaxAuthority;
}
Alrighty! I'll merge it in then.
this seems like #4, no?
@luccasr73 No this is a separate issue. This doesn't allow you to map fields to arbitrary column names.
Anyways, this is fixed and out in version 1.0.9.