From 67466b4968467fe2c75cc88a50779d6b8e0b9579 Mon Sep 17 00:00:00 2001 From: monoid Date: Thu, 7 Nov 2024 05:17:32 +0900 Subject: [PATCH] fix: docuemnt tags zero length insert --- packages/server/src/db/doc.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/server/src/db/doc.ts b/packages/server/src/db/doc.ts index d020259..cd4238e 100644 --- a/packages/server/src/db/doc.ts +++ b/packages/server/src/db/doc.ts @@ -88,12 +88,14 @@ class SqliteDocumentAccessor implements DocumentAccessor { .executeTakeFirst() as { id: number }; const id = id_lst.id; - // add tags - await trx.insertInto("tags") - .values(tags.map((x) => ({ name: x }))) - // on conflict is supported in sqlite and postgresql. - .onConflict((oc) => oc.doNothing()) - .execute(); + if (tags.length > 0){ + // add tags + await trx.insertInto("tags") + .values(tags.map((x) => ({ name: x }))) + // on conflict is supported in sqlite and postgresql. + .onConflict((oc) => oc.doNothing()) + .execute(); + } if (tags.length > 0) { await trx.insertInto("doc_tag_relation") @@ -310,10 +312,12 @@ class SqliteDocumentAccessor implements DocumentAccessor { .where("doc_id", "=", c.id) .execute(); // update tags and doc_tag_relation - await trx.insertInto("tags") - .values(tags.map((x) => ({ name: x }))) - .onConflict((oc) => oc.doNothing()) - .execute(); + if (tags.length > 0) { + await trx.insertInto("tags") + .values(tags.map((x) => ({ name: x }))) + .onConflict((oc) => oc.doNothing()) + .execute(); + } await trx.insertInto("doc_tag_relation") .values(tags.map((x) => ({ tag_name: x, doc_id: c.id })) )