K
Kysely12mo ago
ituriel

How to handle versioning of database objects.

Hello, i want to add versioning for my QuizTemplates. I have an idea with revision field. I want to add new field called "revision" in quizTemplate and quizInstance somehow create join from QuizInstance. How can i create join by two fields instead of one? How do you handle join by more than 1 column. model QuizTemplate { id Int @id @default(autoincrement()) createdAt DateTime @default(now()) title String description String content Json ownerId String // revision Int quizInstances QuizInstance[] } model QuizInstance { id Int @id @default(autoincrement()) createdAt DateTime @default(now()) done Boolean title String description String // revision Int templateId Int quizTemplate QuizTemplate @relation(fields: [templateId], references: [id]) } const quiz = await db .selectFrom("QuizInstance") .innerJoin("QuizTemplate", "QuizTemplate.id", "QuizInstance.templateId") .where("QuizInstance.id", "=", instanceId) .select([ "done", "QuizTemplate.content", "QuizInstance.title", "QuizInstance.description", "QuizInstance.id", ]) .executeTakeFirstOrThrow();
2 Replies
ituriel
iturielOP12mo ago
in raw SQL i can do SELECT * FROM Table1 INNER JOIN Table2 ON Table1.Key1 = Table2.Key1 AND Table1.Key2 = Table2.Key2 AND Table1.Key3 = Table2.Key3 but how to do it in kysely
Want results from more Discord servers?
Add your server