feat: use JSON column + bulk update support.
This commit is contained in:
@@ -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();
|
||||
// }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user