feat: use JSON column + bulk update support.

This commit is contained in:
mattia
2025-01-08 11:49:53 +01:00
parent 0a73fc5a95
commit 15f96b5a7c
7 changed files with 56 additions and 66 deletions

View File

@@ -2,6 +2,7 @@ import { LogEntry, SingleMetadata } from "../contract";
import { HttpError } from "../http-error";
import { db } from "./init";
import { zip } from "lodash-es";
import { json } from "./kysely-mariadb-json";
declare global {
interface BigInt {
@@ -46,8 +47,8 @@ export async function postLog(
version,
})
.execute();
// add the main log line
const insertResult = await trx
// add the main log lines with their metadata
await trx
.insertInto("log_entries")
.values(
entries.map((entry) => ({
@@ -55,30 +56,11 @@ export async function postLog(
message: entry.message,
timestamp: new Date(),
category: entry.category,
metadata: json(entry.metadata.map((x) => [x.key, x.value])),
}))
)
.returning("id")
.execute();
console.log("insertResulttt:", JSON.stringify(insertResult, null, 2));
for (const r of insertResult) {
console.log("insertResult", r.id);
}
// console.log("insertResult.insertId", (insertResult as any).insertId);
// console.log("keys:", Object.keys(insertResult));
throw new Error("aaa");
// add all the metadata
// if (metadata.length > 0) {
// await trx
// .insertInto("log_metadata")
// .values(
// metadata.map(({ key, value }) => ({
// log_entry_id: Number(insertResult.insertId),
// key,
// value,
// }))
// )
// .execute();
// }
});
}
}