K
Join ServerKysely
help
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
while the generated schema is expecting them to not be null
Ah. That's what I'm missing. Silly mistake
Thank you
Actually, I figured out what was really wrong - I shouldn't have had to add an optional on those fields.
I was using
I was using
Selectable<TextDocumentTable>
and Selectable<TextDocumentChunkTable>
for the insert inputs for insertTextDocument
/ insertTextDocumentChunk
when it should be using Insertable
instead of Selectable