Does kysely convert Table names lowercase when it's building a query ?

When I try to run this code it tries to insert into "profile" table not "Profile": Note: I have only extracted important parts
// Kysely codegen output
export interface Profile {
profile_id: Generated<number>;
username: string | null;
created_at: Generated<Date | null>;
updated_at: Generated<Date | null>;
user_id: string | null;
}

// types
type ProfileTable = KeysToCamelCase<Profile>

export type SelectableProfile = Selectable<ProfileTable>
export type InsertableProfile = Insertable<ProfileTable>
export type UpdateableProfile = Updateable<ProfileTable>

export type DB = {
Profile: ProfileTable
}

// connection
export const db = new Kysely<DB>({
dialect: new PlanetScaleDialect({
host: DATABASE_HOST,
username: DATABASE_USERNAME,
password: DATABASE_PASSWORD
}),
plugins: [new CamelCasePlugin()]
})


// repo
export async function createProfile(data: InsertableProfile) {
try {
const response = await db
.insertInto("Profile")
.values(data)
.executeTakeFirst()
return response
} catch (e) {
log.error(e, "Couldn't create profile")
return null
}
}
// Kysely codegen output
export interface Profile {
profile_id: Generated<number>;
username: string | null;
created_at: Generated<Date | null>;
updated_at: Generated<Date | null>;
user_id: string | null;
}

// types
type ProfileTable = KeysToCamelCase<Profile>

export type SelectableProfile = Selectable<ProfileTable>
export type InsertableProfile = Insertable<ProfileTable>
export type UpdateableProfile = Updateable<ProfileTable>

export type DB = {
Profile: ProfileTable
}

// connection
export const db = new Kysely<DB>({
dialect: new PlanetScaleDialect({
host: DATABASE_HOST,
username: DATABASE_USERNAME,
password: DATABASE_PASSWORD
}),
plugins: [new CamelCasePlugin()]
})


// repo
export async function createProfile(data: InsertableProfile) {
try {
const response = await db
.insertInto("Profile")
.values(data)
.executeTakeFirst()
return response
} catch (e) {
log.error(e, "Couldn't create profile")
return null
}
}
3 Replies
koskimas
koskimas11mo ago
You're using the CamelCasePlugin, so yes it does in this case. As it should.
suchcodemuchwow
suchcodemuchwow11mo ago
As far as I can see from the docs https://kysely-org.github.io/kysely/interfaces/CamelCasePluginOptions.html there is no configuration option for keeping table name as it's but camelcasing the column names. Is there a way I can achieve this ?
CamelCasePluginOptions | kysely
Documentation for kysely
koskimas
koskimas11mo ago
Not currently, but we could probably add it easily. Could you open an issue in github?