ooooo just gotta dot notation now

main
Bel LaPointe 2025-04-26 12:47:17 -06:00
parent 61349beb85
commit a199e34730
1 changed files with 53 additions and 45 deletions

View File

@ -95,13 +95,14 @@ type (
Execution struct { Execution struct {
Executed time.Time Executed time.Time
VersionCreated time.Time Version time.Time
} }
) )
func (f *Feeds) Get(ctx context.Context, id string) (Feed, error) { func (f *Feeds) Get(ctx context.Context, id string) (Feed, error) {
return db.QueryOne[Feed](ctx, ` return db.QueryOne[Feed](ctx, `
WITH entry AS ( WITH
entry AS (
SELECT SELECT
id AS ID, id AS ID,
created_at AS Created, created_at AS Created,
@ -109,13 +110,11 @@ func (f *Feeds) Get(ctx context.Context, id string) (Feed, error) {
deleted_at AS Deleted deleted_at AS Deleted
FROM "feed.entries" FROM "feed.entries"
WHERE id = ? WHERE id = ?
), WITH version AS ( ),
execution AS (
SELECT SELECT
TODO executed_at AS Executed,
FROM "feed.versions" versions_created_at AS Version
), WITH execution AS (
SELECT
TODO
FROM "feed.executions" FROM "feed.executions"
WHERE entries_id = ? WHERE entries_id = ?
ORDER BY executed DESC ORDER BY executed DESC
@ -126,14 +125,29 @@ func (f *Feeds) Get(ctx context.Context, id string) (Feed, error) {
entry.Created AS "Entry.Created", entry.Created AS "Entry.Created",
entry.Updated AS "Entry.Updated", entry.Updated AS "Entry.Updated",
entry.Deleted AS "Entry.Deleted", entry.Deleted AS "Entry.Deleted",
version.Created AS "Version.Created", versions.created_at AS "Version.Created",
version.URL AS "Version.URL", versions.url AS "Version.URL",
version.Cron AS "Version.Cron", versions.cron AS "Version.Cron",
execution.Executed AS "", (
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 FROM entry
FROM version JOIN "feed.versions" version_entries_id ON
FROM execution 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) { func (f *Feeds) oldGet(ctx context.Context, id string) (Feed, error) {
@ -195,17 +209,11 @@ func (f *Feeds) Insert(ctx context.Context, url, cron string) (string, error) {
url, url,
cron cron
) VALUES (?, ?, ?, ?); ) VALUES (?, ?, ?, ?);
INSERT INTO "feed.current_versions" (
entries_id,
versions_created_at,
updated_at
) VALUES (?, ?, ?);
COMMIT; COMMIT;
` `
return id, db.Exec(ctx, q, return id, db.Exec(ctx, q,
id, now, now, id, now, now,
id, now, url, cron, id, now, url, cron,
id, now, now,
) )
} }