KyselyK
Kysely3y ago
Theo

In a transaction, how do you ignore generated field requirements?

export interface TextDocumentTable {
  id: Generated<number>;
  created_at: Generated<Date>;
}

export interface TextDocumentChunkTable {
  id: Generated<number>;
  text_document_id: number;
  created_at: Generated<Date>;
  text: string;
}

export type TextDocumentRow = Selectable<TextDocumentTable>;
export type TextDocumentChunkRow = Selectable<TextDocumentChunkTable>;


await this.db.transaction().execute(async (trx) => {

  // 2nd param is TextDocumentRow
  const insertedTextDocument = await insertTextDocument(trx, document);

  // 2nd param is TextDocumentChunkRow
  await insertTextDocumentChunk(trx, {
    text_document_id: insertedTextDocument.id,
    text: document.text_content,
  });
});


Typescript will complain that insertTextDocumentChunk needs id and created_at even though they are Generated values.
Solution
im assuming id/created_at are nullable on document
Was this page helpful?