insert query in kysely, typerror

Hi, I try to migrate from prisma to kysely, only use Prisma for generating the types. Currently I have a insert into db like this with prisma api
ts await ctx.prisma.voteAnime.create({
data: {
votedAgainstId: input.votedAgainst,
votedForId: input.votedFor,
},
});
ts await ctx.prisma.voteAnime.create({
data: {
votedAgainstId: input.votedAgainst,
votedForId: input.votedFor,
},
});
I tried to do it like this with Kysely
ts const result = await ctx.db
.insertInto("VoteAnime")
.values({
votedAgainstId: input.votedAgainst,
votedForId: input.votedFor,
})
.executeTakeFirst();
ts const result = await ctx.db
.insertInto("VoteAnime")
.values({
votedAgainstId: input.votedAgainst,
votedForId: input.votedFor,
})
.executeTakeFirst();
but it gives me errors: Object literal may only specify known properties, and 'votedAgainstId' does not exist in type 'InsertObjectOrListFactory<Database, "VoteAnime">'. Anyone maybe know how to fix this?
2 Replies
noctate
noctateOP•2y ago
to give more context the this is vote anime type:
type VoteAnime = {
id: string
createdAt: Date
votedForId: number
votedAgainstId: number
animeId: number | null
}
type VoteAnime = {
id: string
createdAt: Date
votedForId: number
votedAgainstId: number
animeId: number | null
}
after some research I changed the type to this interface
VoteAnime {
id: Generated<string>;
votedForId: number;
votedAgainstId: number;
createdAt: Generated<Date>;
}
VoteAnime {
id: Generated<string>;
votedForId: number;
votedAgainstId: number;
createdAt: Generated<Date>;
}
but now I get error: Field 'id' doesn't have a default value when trying to fire mutation. when constructing the prisma schema and pushing it to database I chosed
id String @id @default(cuid())
id String @id @default(cuid())
so I guess it should have a default value?
Igal
Igal•2y ago
Hey 👋 You should try https://github.com/valtyr/prisma-kysely to not manage Kysely types yourself. Also check out this section https://github.com/valtyr/prisma-kysely#gotchas, related to default values and why you're getting doesn't have a default value errors.
GitHub
GitHub - valtyr/prisma-kysely: 🪄 Generate Kysely types directly fro...
🪄 Generate Kysely types directly from your Prisma schema! - GitHub - valtyr/prisma-kysely: 🪄 Generate Kysely types directly from your Prisma schema!
Want results from more Discord servers?
Add your server