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