extra wrapping so not json array in db

This commit is contained in:
dylan 2024-03-31 17:57:23 -07:00
parent a3b07d6028
commit e5039232c8

View File

@ -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<DbRelease[]> => {
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;
}