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

@@ -13,22 +13,11 @@ export async function getSession(id: string): Promise<GetSessionResponse> {
const logEntries = await db
.selectFrom("log_entries")
.where("session_info_id", "=", id)
.select(["id", "message", "timestamp", "category"])
.select(["id", "message", "timestamp", "category", "metadata"])
.orderBy("timestamp", "asc")
.execute();
// get all the metadata for the log entries
const metadata = await db
.selectFrom("log_metadata")
.where(
"log_entry_id",
"in",
logEntries.map((entry) => entry.id)
)
.select(["log_entry_id", "key", "value"])
.execute();
// buidl the object accordingly
// build the object accordingly
return {
game_name: session.game_name,
version: session.version,
@@ -36,9 +25,10 @@ export async function getSession(id: string): Promise<GetSessionResponse> {
message: entry.message,
timestamp: entry.timestamp,
category: entry.category,
metadata: metadata
.filter((m) => m.log_entry_id === entry.id)
.reduce((acc, m) => ({ ...acc, [m.key]: m.value }), {}),
metadata: entry.metadata.reduce(
(acc, m) => ({ ...acc, [m[0]]: m[1] }),
{}
),
})),
};
}