From c7d4ffa9dde1d305770e546058d370813e344eee Mon Sep 17 00:00:00 2001 From: dylan <> Date: Sun, 31 Mar 2024 17:36:55 -0700 Subject: [PATCH 1/7] oops, missing comma --- src/server/dbal/dbal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/dbal/dbal.ts b/src/server/dbal/dbal.ts index eb14324..089da14 100644 --- a/src/server/dbal/dbal.ts +++ b/src/server/dbal/dbal.ts @@ -83,7 +83,7 @@ export const insertRelease = async (props: {manifest: PicobookManifest, carts: { const now = new Date(); await db.query(sql` INSERT INTO chats (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; } From b37d5933a722597678c9cbb0a734b5220fe9e74f Mon Sep 17 00:00:00 2001 From: dylan <> Date: Sun, 31 Mar 2024 17:38:14 -0700 Subject: [PATCH 2/7] oops, wrong table name --- src/server/dbal/dbal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/dbal/dbal.ts b/src/server/dbal/dbal.ts index 089da14..9726d96 100644 --- a/src/server/dbal/dbal.ts +++ b/src/server/dbal/dbal.ts @@ -82,7 +82,7 @@ export const insertRelease = async (props: {manifest: PicobookManifest, carts: { const id = uuidv4(); const now = new Date(); await db.query(sql` - INSERT INTO chats (id, slug, repo, version, author, carts, manifest, created_at) + INSERT INTO releases (id, slug, repo, version, author, carts, manifest, created_at) VALUES (${id}, ${slug}, ${repo}, ${version}, ${author}, ${carts}, ${manifest}, ${now}) `); return id; From 7fec78ff8490e79e9efee91ca23b263c5468506d Mon Sep 17 00:00:00 2001 From: dylan <> Date: Sun, 31 Mar 2024 17:42:07 -0700 Subject: [PATCH 3/7] stringify json? --- src/server/dbal/dbal.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/server/dbal/dbal.ts b/src/server/dbal/dbal.ts index 9726d96..ca70705 100644 --- a/src/server/dbal/dbal.ts +++ b/src/server/dbal/dbal.ts @@ -1,9 +1,7 @@ // Database Access Layer stuff goes here -// Database Access Layer stuff goes here import { v4 as uuidv4 } from 'uuid'; -import { db, sql } from "../../database/db" -import { JsonValue } from '@firebox/tsutil'; +import { db, sql } from "../../database/db"; import { PicobookManifest } from '../types'; export type DbRelease = { @@ -78,12 +76,13 @@ export const getRelease = async (where: { export const insertRelease = async (props: {manifest: PicobookManifest, carts: {name: string; rom: number[]}[]}) => { const {manifest, carts} = props; + console.log('carts', JSON.stringify(carts)); const {id: slug, author, repo, version} = manifest; const id = uuidv4(); 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}, ${JSON.stringify(carts)}, ${manifest}, ${now}) `); return id; } From 008e5777c5b7c4ebab90f63269323203382fa42b Mon Sep 17 00:00:00 2001 From: dylan <> Date: Sun, 31 Mar 2024 17:44:52 -0700 Subject: [PATCH 4/7] await the insertion --- src/server/api/release.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/api/release.ts b/src/server/api/release.ts index 31f9248..04f4e87 100644 --- a/src/server/api/release.ts +++ b/src/server/api/release.ts @@ -38,7 +38,7 @@ const handler = async ({payload}: FirRouteInput) => { const carts = await getCarts(repoPath, manifest.carts); - insertRelease({ + await insertRelease({ manifest, carts, }); From a3b07d602873f7fd1c9658f1afb90ce421688e14 Mon Sep 17 00:00:00 2001 From: dylan <> Date: Sun, 31 Mar 2024 17:49:50 -0700 Subject: [PATCH 5/7] created_at -> timestamp --- src/database/migrations/5-fifth-migration.sql | 2 ++ src/server/dbal/dbal.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 src/database/migrations/5-fifth-migration.sql diff --git a/src/database/migrations/5-fifth-migration.sql b/src/database/migrations/5-fifth-migration.sql new file mode 100644 index 0000000..707b828 --- /dev/null +++ b/src/database/migrations/5-fifth-migration.sql @@ -0,0 +1,2 @@ +ALTER TABLE releases DROP COLUMN created_at; +ALTER TABLE releases ADD created_at timestamp; diff --git a/src/server/dbal/dbal.ts b/src/server/dbal/dbal.ts index ca70705..70411ed 100644 --- a/src/server/dbal/dbal.ts +++ b/src/server/dbal/dbal.ts @@ -76,13 +76,13 @@ export const getRelease = async (where: { export const insertRelease = async (props: {manifest: PicobookManifest, carts: {name: string; rom: number[]}[]}) => { const {manifest, carts} = props; - console.log('carts', JSON.stringify(carts)); + // console.log('carts', JSON.stringify(carts)); const {id: slug, author, repo, version} = manifest; const id = uuidv4(); 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}, ${JSON.stringify(carts)}, ${manifest}, ${now}) + VALUES (${id}, ${slug}, ${repo}, ${version}, ${author}, ${carts}, ${manifest}, ${now}) `); return id; } From e5039232c8648264c876d44435bab3eb6fd6d088 Mon Sep 17 00:00:00 2001 From: dylan <> Date: Sun, 31 Mar 2024 17:57:23 -0700 Subject: [PATCH 6/7] 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; } From f17578af17ead24d2525632509a923c1e8a28af6 Mon Sep 17 00:00:00 2001 From: dylan <> Date: Sun, 31 Mar 2024 17:59:12 -0700 Subject: [PATCH 7/7] register getRelease route --- src/server/routelist.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/server/routelist.ts b/src/server/routelist.ts index 58a6424..6cb1aec 100644 --- a/src/server/routelist.ts +++ b/src/server/routelist.ts @@ -1,4 +1,5 @@ import echo from "./api/echo.ts"; +import getRelease from "./api/getRelease.ts"; import release from "./api/release.ts"; import webhook from "./api/webhook.ts"; @@ -6,6 +7,7 @@ export const routeList = [ echo, webhook, release, + getRelease, ]; export type RouteList = typeof routeList; \ No newline at end of file