@@ -63,6 +63,17 @@ func (q *Queries) ClaimDueDeliveries(ctx context.Context, db DBTX, limit int32) |
| 63 | return items, nil | 63 | return items, nil |
| 64 | } | 64 | } |
| 65 | | 65 | |
| | 66 | +const countDeliveriesForWebhook = `-- name: CountDeliveriesForWebhook :one |
| | 67 | +SELECT count(*)::bigint FROM webhook_deliveries WHERE webhook_id = $1 |
| | 68 | +` |
| | 69 | + |
| | 70 | +func (q *Queries) CountDeliveriesForWebhook(ctx context.Context, db DBTX, webhookID int64) (int64, error) { |
| | 71 | + row := db.QueryRow(ctx, countDeliveriesForWebhook, webhookID) |
| | 72 | + var column_1 int64 |
| | 73 | + err := row.Scan(&column_1) |
| | 74 | + return column_1, err |
| | 75 | +} |
| | 76 | + |
| 66 | const createDelivery = `-- name: CreateDelivery :one | 77 | const createDelivery = `-- name: CreateDelivery :one |
| 67 | INSERT INTO webhook_deliveries ( | 78 | INSERT INTO webhook_deliveries ( |
| 68 | webhook_id, event_kind, event_id, payload, request_headers, | 79 | webhook_id, event_kind, event_id, payload, request_headers, |
@@ -403,6 +414,78 @@ func (q *Queries) ListDeliveriesForWebhook(ctx context.Context, db DBTX, arg Lis |
| 403 | return items, nil | 414 | return items, nil |
| 404 | } | 415 | } |
| 405 | | 416 | |
| | 417 | +const listDeliveriesForWebhookPaged = `-- name: ListDeliveriesForWebhookPaged :many |
| | 418 | +SELECT id, webhook_id, event_kind, event_id, delivery_uuid, response_status, |
| | 419 | + response_truncated, started_at, completed_at, attempt, max_attempts, |
| | 420 | + next_retry_at, status, error_summary, redeliver_of |
| | 421 | +FROM webhook_deliveries |
| | 422 | +WHERE webhook_id = $1 |
| | 423 | +ORDER BY started_at DESC |
| | 424 | +LIMIT $2 OFFSET $3 |
| | 425 | +` |
| | 426 | + |
| | 427 | +type ListDeliveriesForWebhookPagedParams struct { |
| | 428 | + WebhookID int64 |
| | 429 | + Limit int32 |
| | 430 | + Offset int32 |
| | 431 | +} |
| | 432 | + |
| | 433 | +type ListDeliveriesForWebhookPagedRow struct { |
| | 434 | + ID int64 |
| | 435 | + WebhookID int64 |
| | 436 | + EventKind string |
| | 437 | + EventID pgtype.Int8 |
| | 438 | + DeliveryUuid pgtype.UUID |
| | 439 | + ResponseStatus pgtype.Int4 |
| | 440 | + ResponseTruncated bool |
| | 441 | + StartedAt pgtype.Timestamptz |
| | 442 | + CompletedAt pgtype.Timestamptz |
| | 443 | + Attempt int32 |
| | 444 | + MaxAttempts int32 |
| | 445 | + NextRetryAt pgtype.Timestamptz |
| | 446 | + Status WebhookDeliveryStatus |
| | 447 | + ErrorSummary pgtype.Text |
| | 448 | + RedeliverOf pgtype.Int8 |
| | 449 | +} |
| | 450 | + |
| | 451 | +// Paginated mirror of ListDeliveriesForWebhook for the REST surface. |
| | 452 | +// Order matches the unpaginated form so callers can swap freely. |
| | 453 | +func (q *Queries) ListDeliveriesForWebhookPaged(ctx context.Context, db DBTX, arg ListDeliveriesForWebhookPagedParams) ([]ListDeliveriesForWebhookPagedRow, error) { |
| | 454 | + rows, err := db.Query(ctx, listDeliveriesForWebhookPaged, arg.WebhookID, arg.Limit, arg.Offset) |
| | 455 | + if err != nil { |
| | 456 | + return nil, err |
| | 457 | + } |
| | 458 | + defer rows.Close() |
| | 459 | + items := []ListDeliveriesForWebhookPagedRow{} |
| | 460 | + for rows.Next() { |
| | 461 | + var i ListDeliveriesForWebhookPagedRow |
| | 462 | + if err := rows.Scan( |
| | 463 | + &i.ID, |
| | 464 | + &i.WebhookID, |
| | 465 | + &i.EventKind, |
| | 466 | + &i.EventID, |
| | 467 | + &i.DeliveryUuid, |
| | 468 | + &i.ResponseStatus, |
| | 469 | + &i.ResponseTruncated, |
| | 470 | + &i.StartedAt, |
| | 471 | + &i.CompletedAt, |
| | 472 | + &i.Attempt, |
| | 473 | + &i.MaxAttempts, |
| | 474 | + &i.NextRetryAt, |
| | 475 | + &i.Status, |
| | 476 | + &i.ErrorSummary, |
| | 477 | + &i.RedeliverOf, |
| | 478 | + ); err != nil { |
| | 479 | + return nil, err |
| | 480 | + } |
| | 481 | + items = append(items, i) |
| | 482 | + } |
| | 483 | + if err := rows.Err(); err != nil { |
| | 484 | + return nil, err |
| | 485 | + } |
| | 486 | + return items, nil |
| | 487 | +} |
| | 488 | + |
| 406 | const listWebhooksForOwner = `-- name: ListWebhooksForOwner :many | 489 | const listWebhooksForOwner = `-- name: ListWebhooksForOwner :many |
| 407 | SELECT id, owner_kind, owner_id, url, content_type, events, secret_ciphertext, secret_nonce, active, ssl_verification, consecutive_failures, auto_disable_threshold, disabled_at, disabled_reason, last_success_at, last_failure_at, created_by_user_id, created_at, updated_at FROM webhooks | 490 | SELECT id, owner_kind, owner_id, url, content_type, events, secret_ciphertext, secret_nonce, active, ssl_verification, consecutive_failures, auto_disable_threshold, disabled_at, disabled_reason, last_success_at, last_failure_at, created_by_user_id, created_at, updated_at FROM webhooks |
| 408 | WHERE owner_kind = $1 AND owner_id = $2 | 491 | WHERE owner_kind = $1 AND owner_id = $2 |