From a199e34730b36bec17610685b7968aa9c3c927b4 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Sat, 26 Apr 2025 12:47:17 -0600 Subject: [PATCH] ooooo just gotta dot notation now --- src/feeds/db.go | 98 ++++++++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/src/feeds/db.go b/src/feeds/db.go index 590398c..cccedce 100644 --- a/src/feeds/db.go +++ b/src/feeds/db.go @@ -94,46 +94,60 @@ type ( } Execution struct { - Executed time.Time - VersionCreated time.Time + Executed time.Time + Version time.Time } ) func (f *Feeds) Get(ctx context.Context, id string) (Feed, error) { return db.QueryOne[Feed](ctx, ` - WITH entry AS ( - SELECT - id AS ID, - created_at AS Created, - updated_at AS Updated, - deleted_at AS Deleted - FROM "feed.entries" - WHERE id = ? - ), WITH version AS ( - SELECT - TODO - FROM "feed.versions" - ), WITH execution AS ( - SELECT - TODO - FROM "feed.executions" - WHERE entries_id = ? - ORDER BY executed DESC - LIMIT 1 - ) - SELECT - entry.ID AS "Entry.ID", - entry.Created AS "Entry.Created", - entry.Updated AS "Entry.Updated", - entry.Deleted AS "Entry.Deleted", - version.Created AS "Version.Created", - version.URL AS "Version.URL", - version.Cron AS "Version.Cron", - execution.Executed AS "", - FROM entry - FROM version - FROM execution - `) + WITH + entry AS ( + SELECT + id AS ID, + created_at AS Created, + updated_at AS Updated, + deleted_at AS Deleted + FROM "feed.entries" + WHERE id = ? + ), + execution AS ( + SELECT + executed_at AS Executed, + versions_created_at AS Version + FROM "feed.executions" + WHERE entries_id = ? + ORDER BY executed DESC + LIMIT 1 + ) + SELECT + entry.ID AS "Entry.ID", + entry.Created AS "Entry.Created", + entry.Updated AS "Entry.Updated", + entry.Deleted AS "Entry.Deleted", + versions.created_at AS "Version.Created", + versions.url AS "Version.URL", + versions.cron AS "Version.Cron", + ( + SELECT executed_at + FROM "feed.executions" + WHERE entries_id = entry.ID + ORDER BY executed_at DESC + LIMIT 1 + ) AS "Execution.Executed", + ( + SELECT versions_created_at + FROM "feed.executions" + WHERE entries_id = entry.ID + ORDER BY executed_at DESC + LIMIT 1 + ) AS "Execution.Version" + FROM entry + JOIN "feed.versions" version_entries_id ON + version_entries_id.entries_id=entry.ID + JOIN "feed.versions" versions ON + versions.created_at=entry.Updated + `, id, id) } func (f *Feeds) oldGet(ctx context.Context, id string) (Feed, error) { @@ -148,12 +162,12 @@ func (f *Feeds) oldGet(ctx context.Context, id string) (Feed, error) { "feed.current_versions" AS URL, "feed.current_versions" AS Cron FROM - "feed.current_versions" + "feed.current_versions" JOIN - "feed.versions" versions_a ON + "feed.versions" versions_a ON "feed.current_versions".entries_id=versions_a.entries_id JOIN - "feed.versions" versions_b ON + "feed.versions" versions_b ON "feed.current_versions".versions_created_at=versions_b.created_at WHERE "feed.current_versions".entries_id = ? @@ -167,7 +181,7 @@ func (f *Feeds) oldGet(ctx context.Context, id string) (Feed, error) { "feed.executed_at" AS Executed, "feed.versions_created_at" AS VersionsCreated FROM - "feed.executions" + "feed.executions" WHERE "feed.executions".entries_id = ? ORDER BY "feed.executions".executed_at DESC @@ -195,17 +209,11 @@ func (f *Feeds) Insert(ctx context.Context, url, cron string) (string, error) { url, cron ) VALUES (?, ?, ?, ?); - INSERT INTO "feed.current_versions" ( - entries_id, - versions_created_at, - updated_at - ) VALUES (?, ?, ?); COMMIT; ` return id, db.Exec(ctx, q, id, now, now, id, now, url, cron, - id, now, now, ) }