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 {
Executed time.Time
VersionCreated time.Time
Version time.Time
}
)
func (f *Feeds) Get(ctx context.Context, id string) (Feed, error) {
return db.QueryOne[Feed](ctx, `
WITH entry AS (
WITH
entry AS (
SELECT
id AS ID,
created_at AS Created,
@ -109,13 +110,11 @@ func (f *Feeds) Get(ctx context.Context, id string) (Feed, error) {
deleted_at AS Deleted
FROM "feed.entries"
WHERE id = ?
), WITH version AS (
),
execution AS (
SELECT
TODO
FROM "feed.versions"
), WITH execution AS (
SELECT
TODO
executed_at AS Executed,
versions_created_at AS Version
FROM "feed.executions"
WHERE entries_id = ?
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.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 "",
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
FROM version
FROM execution
`)
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) {
@ -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,
)
}