Compare commits

..

2 Commits

Author SHA1 Message Date
monoid
05c59937e9 feat: kysely detail logs on error 2024-11-07 05:18:01 +09:00
monoid
67466b4968 fix: docuemnt tags zero length insert 2024-11-07 05:17:32 +09:00
2 changed files with 25 additions and 11 deletions

View File

@ -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 }))
)

View File

@ -22,7 +22,17 @@ export function getKysely() {
kysely = new Kysely<DB>({
dialect: createSqliteDialect(),
// plugins: [new ParseJSONResultsPlugin()],
log: (event) => {
if (event.level === "error") {
console.error("Query failed : ", {
durationMs: event.queryDurationMillis,
error: event.error,
sql: event.query.sql,
params: event.query.parameters,
});
}
}
});
}
return kysely;
}
}