ooooo just gotta dot notation now
parent
61349beb85
commit
a199e34730
|
|
@ -94,46 +94,60 @@ 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
|
||||||
SELECT
|
entry AS (
|
||||||
id AS ID,
|
SELECT
|
||||||
created_at AS Created,
|
id AS ID,
|
||||||
updated_at AS Updated,
|
created_at AS Created,
|
||||||
deleted_at AS Deleted
|
updated_at AS Updated,
|
||||||
FROM "feed.entries"
|
deleted_at AS Deleted
|
||||||
WHERE id = ?
|
FROM "feed.entries"
|
||||||
), WITH version AS (
|
WHERE id = ?
|
||||||
SELECT
|
),
|
||||||
TODO
|
execution AS (
|
||||||
FROM "feed.versions"
|
SELECT
|
||||||
), WITH execution AS (
|
executed_at AS Executed,
|
||||||
SELECT
|
versions_created_at AS Version
|
||||||
TODO
|
FROM "feed.executions"
|
||||||
FROM "feed.executions"
|
WHERE entries_id = ?
|
||||||
WHERE entries_id = ?
|
ORDER BY executed DESC
|
||||||
ORDER BY executed DESC
|
LIMIT 1
|
||||||
LIMIT 1
|
)
|
||||||
)
|
SELECT
|
||||||
SELECT
|
entry.ID AS "Entry.ID",
|
||||||
entry.ID AS "Entry.ID",
|
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",
|
versions.created_at AS "Version.Created",
|
||||||
version.Created AS "Version.Created",
|
versions.url AS "Version.URL",
|
||||||
version.URL AS "Version.URL",
|
versions.cron AS "Version.Cron",
|
||||||
version.Cron AS "Version.Cron",
|
(
|
||||||
execution.Executed AS "",
|
SELECT executed_at
|
||||||
FROM entry
|
FROM "feed.executions"
|
||||||
FROM version
|
WHERE entries_id = entry.ID
|
||||||
FROM execution
|
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) {
|
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 URL,
|
||||||
"feed.current_versions" AS Cron
|
"feed.current_versions" AS Cron
|
||||||
FROM
|
FROM
|
||||||
"feed.current_versions"
|
"feed.current_versions"
|
||||||
JOIN
|
JOIN
|
||||||
"feed.versions" versions_a ON
|
"feed.versions" versions_a ON
|
||||||
"feed.current_versions".entries_id=versions_a.entries_id
|
"feed.current_versions".entries_id=versions_a.entries_id
|
||||||
JOIN
|
JOIN
|
||||||
"feed.versions" versions_b ON
|
"feed.versions" versions_b ON
|
||||||
"feed.current_versions".versions_created_at=versions_b.created_at
|
"feed.current_versions".versions_created_at=versions_b.created_at
|
||||||
WHERE
|
WHERE
|
||||||
"feed.current_versions".entries_id = ?
|
"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.executed_at" AS Executed,
|
||||||
"feed.versions_created_at" AS VersionsCreated
|
"feed.versions_created_at" AS VersionsCreated
|
||||||
FROM
|
FROM
|
||||||
"feed.executions"
|
"feed.executions"
|
||||||
WHERE
|
WHERE
|
||||||
"feed.executions".entries_id = ?
|
"feed.executions".entries_id = ?
|
||||||
ORDER BY "feed.executions".executed_at DESC
|
ORDER BY "feed.executions".executed_at DESC
|
||||||
|
|
@ -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,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue