From e5039232c8648264c876d44435bab3eb6fd6d088 Mon Sep 17 00:00:00 2001 From: dylan <> Date: Sun, 31 Mar 2024 17:57:23 -0700 Subject: [PATCH] extra wrapping so not json array in db --- src/server/dbal/dbal.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/server/dbal/dbal.ts b/src/server/dbal/dbal.ts index 70411ed..edfb45e 100644 --- a/src/server/dbal/dbal.ts +++ b/src/server/dbal/dbal.ts @@ -14,6 +14,16 @@ export type DbRelease = { manifest: PicobookManifest; } +export type DbReleaseInternal = { + id: string; + slug: string; + repo: string; + version: string; + carts: {carts: {name: string; rom: number[]}[]}; + author: string; + manifest: PicobookManifest; +} + const compareVersions = (a: string, b: string) => { const [a1, a2] = a.split(".").map(x => Number(x)); const [b1, b2] = b.split(".").map(x => Number(x)); @@ -32,24 +42,24 @@ export const getReleases = async (where: { version?: string; }): Promise => { const {author, slug, version} = where; + let rows: DbReleaseInternal[]; if (!version) { - const rows = await db.query(sql` + rows = await db.query(sql` SELECT * from releases WHERE slug = ${slug} AND author = ${author} `); - return rows; } else { - const rows = await db.query(sql` + rows = await db.query(sql` SELECT * from releases WHERE slug = ${slug} AND author = ${author} AND version = ${version} `); - return rows; } + return rows.map(row => ({...row, carts: row.carts.carts})); } export const getRelease = async (where: { @@ -82,7 +92,7 @@ export const insertRelease = async (props: {manifest: PicobookManifest, carts: { const now = new Date(); await db.query(sql` INSERT INTO releases (id, slug, repo, version, author, carts, manifest, created_at) - VALUES (${id}, ${slug}, ${repo}, ${version}, ${author}, ${carts}, ${manifest}, ${now}) + VALUES (${id}, ${slug}, ${repo}, ${version}, ${author}, ${{carts}}, ${manifest}, ${now}) `); return id; }