Files
lincodex/backend/internal/adapter/secondary/postgres/sqlc/invitation_expiry.sql.go
T

74 lines
2.0 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: invitation_expiry.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const expireInvitation = `-- name: ExpireInvitation :one
UPDATE invitations
SET
state = 'expired',
expiry_reason = 'invitation_timeout',
version = $1,
updated_at = $2
WHERE
organization_id = $3
AND id = $4
AND state IN ('delivered', 'viewed')
AND version = $5
AND response_deadline_at <= $2
AND $1::bigint = $5::bigint + 1
RETURNING id
`
type ExpireInvitationParams struct {
NextVersion int64
ExpiredAt pgtype.Timestamptz
OrganizationID pgtype.UUID
InvitationID pgtype.UUID
ExpectedVersion int64
}
// The compare-and-swap of the expiry: it applies only to a delivered or viewed
// invitation at the version the caller read, whose deadline has passed at the
// expiry time. It keeps the deadline, the terms, and every answer field, and it
// sets the timeout reason. No row is returned when it lost a race or the
// deadline has not passed.
func (q *Queries) ExpireInvitation(ctx context.Context, arg ExpireInvitationParams) (pgtype.UUID, error) {
row := q.db.QueryRow(ctx, expireInvitation,
arg.NextVersion,
arg.ExpiredAt,
arg.OrganizationID,
arg.InvitationID,
arg.ExpectedVersion,
)
var id pgtype.UUID
err := row.Scan(&id)
return id, err
}
const lockInvitationByID = `-- name: LockInvitationByID :one
SELECT organization_id
FROM invitations
WHERE id = $1
FOR UPDATE
`
// Takes the row lock of one invitation by its identifier alone. Only the
// response deadline job reads an invitation without an organization or a
// candidate of the request; it reads the organization from this row and then
// reads the locked invitation with its scope.
func (q *Queries) LockInvitationByID(ctx context.Context, invitationID pgtype.UUID) (pgtype.UUID, error) {
row := q.db.QueryRow(ctx, lockInvitationByID, invitationID)
var organization_id pgtype.UUID
err := row.Scan(&organization_id)
return organization_id, err
}