feat(store): schedules, notification_channels, domain last_check_status + методы
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: schedules.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const getSchedule = `-- name: GetSchedule :one
|
||||
SELECT id, project_id, interval_seconds, enabled, last_run_at, created_at FROM schedules WHERE project_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetSchedule(ctx context.Context, projectID uuid.UUID) (Schedule, error) {
|
||||
row := q.db.QueryRow(ctx, getSchedule, projectID)
|
||||
var i Schedule
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.IntervalSeconds,
|
||||
&i.Enabled,
|
||||
&i.LastRunAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listDueSchedules = `-- name: ListDueSchedules :many
|
||||
SELECT id, project_id, interval_seconds, enabled, last_run_at, created_at FROM schedules
|
||||
WHERE enabled AND (last_run_at IS NULL OR last_run_at + (interval_seconds || ' seconds')::interval <= $1)
|
||||
`
|
||||
|
||||
func (q *Queries) ListDueSchedules(ctx context.Context, lastRunAt pgtype.Timestamptz) ([]Schedule, error) {
|
||||
rows, err := q.db.Query(ctx, listDueSchedules, lastRunAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Schedule
|
||||
for rows.Next() {
|
||||
var i Schedule
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.IntervalSeconds,
|
||||
&i.Enabled,
|
||||
&i.LastRunAt,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const touchScheduleRun = `-- name: TouchScheduleRun :exec
|
||||
UPDATE schedules SET last_run_at = $2 WHERE project_id = $1
|
||||
`
|
||||
|
||||
type TouchScheduleRunParams struct {
|
||||
ProjectID uuid.UUID `json:"project_id"`
|
||||
LastRunAt pgtype.Timestamptz `json:"last_run_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) TouchScheduleRun(ctx context.Context, arg TouchScheduleRunParams) error {
|
||||
_, err := q.db.Exec(ctx, touchScheduleRun, arg.ProjectID, arg.LastRunAt)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertSchedule = `-- name: UpsertSchedule :one
|
||||
INSERT INTO schedules (id, project_id, interval_seconds, enabled)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT (project_id) DO UPDATE SET interval_seconds = $3, enabled = $4
|
||||
RETURNING id, project_id, interval_seconds, enabled, last_run_at, created_at
|
||||
`
|
||||
|
||||
type UpsertScheduleParams struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
ProjectID uuid.UUID `json:"project_id"`
|
||||
IntervalSeconds int32 `json:"interval_seconds"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertSchedule(ctx context.Context, arg UpsertScheduleParams) (Schedule, error) {
|
||||
row := q.db.QueryRow(ctx, upsertSchedule,
|
||||
arg.ID,
|
||||
arg.ProjectID,
|
||||
arg.IntervalSeconds,
|
||||
arg.Enabled,
|
||||
)
|
||||
var i Schedule
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ProjectID,
|
||||
&i.IntervalSeconds,
|
||||
&i.Enabled,
|
||||
&i.LastRunAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in New Issue
Block a user