#12 - update feeds
This commit is contained in:
@@ -22,7 +22,7 @@ VALUES (
|
||||
$5,
|
||||
$6
|
||||
)
|
||||
RETURNING id, created_at, updated_at, name, url, user_id
|
||||
RETURNING id, created_at, updated_at, name, url, user_id, last_fetched_at
|
||||
`
|
||||
|
||||
type CreateFeedParams struct {
|
||||
@@ -51,6 +51,7 @@ func (q *Queries) CreateFeed(ctx context.Context, arg CreateFeedParams) (Feed, e
|
||||
&i.Name,
|
||||
&i.Url,
|
||||
&i.UserID,
|
||||
&i.LastFetchedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
const getFeedByUrl = `-- name: GetFeedByUrl :one
|
||||
SELECT id, created_at, updated_at, name, url, user_id FROM feeds WHERE url = $1
|
||||
SELECT id, created_at, updated_at, name, url, user_id, last_fetched_at FROM feeds WHERE url = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetFeedByUrl(ctx context.Context, url string) (Feed, error) {
|
||||
@@ -23,6 +23,7 @@ func (q *Queries) GetFeedByUrl(ctx context.Context, url string) (Feed, error) {
|
||||
&i.Name,
|
||||
&i.Url,
|
||||
&i.UserID,
|
||||
&i.LastFetchedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
29
internal/database/getNextFeedToFetch.sql.go
Normal file
29
internal/database/getNextFeedToFetch.sql.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// source: getNextFeedToFetch.sql
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const getNextFeedToFetch = `-- name: GetNextFeedToFetch :one
|
||||
SELECT id, created_at, updated_at, name, url, user_id, last_fetched_at FROM feeds ORDER BY last_fetched_at NULLS FIRST LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetNextFeedToFetch(ctx context.Context) (Feed, error) {
|
||||
row := q.db.QueryRowContext(ctx, getNextFeedToFetch)
|
||||
var i Feed
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Name,
|
||||
&i.Url,
|
||||
&i.UserID,
|
||||
&i.LastFetchedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
32
internal/database/markFeeedFetched.sql.go
Normal file
32
internal/database/markFeeedFetched.sql.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// source: markFeeedFetched.sql
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const markFeedFetched = `-- name: MarkFeedFetched :one
|
||||
UPDATE feeds SET last_fetched_at = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP WHERE id = $1
|
||||
RETURNING id, created_at, updated_at, name, url, user_id, last_fetched_at
|
||||
`
|
||||
|
||||
func (q *Queries) MarkFeedFetched(ctx context.Context, id uuid.UUID) (Feed, error) {
|
||||
row := q.db.QueryRowContext(ctx, markFeedFetched, id)
|
||||
var i Feed
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Name,
|
||||
&i.Url,
|
||||
&i.UserID,
|
||||
&i.LastFetchedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -5,18 +5,20 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Feed struct {
|
||||
ID uuid.UUID
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Name string
|
||||
Url string
|
||||
UserID uuid.UUID
|
||||
ID uuid.UUID
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Name string
|
||||
Url string
|
||||
UserID uuid.UUID
|
||||
LastFetchedAt sql.NullTime
|
||||
}
|
||||
|
||||
type FeedFollow struct {
|
||||
|
||||
Reference in New Issue
Block a user