324 lines
8.9 KiB
Go
324 lines
8.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: company_quota.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const countCompanyCardViewQuotaWindow = `-- name: CountCompanyCardViewQuotaWindow :one
|
|
SELECT
|
|
count(*)::bigint AS usage_count,
|
|
min(last_seen_at) AS earliest_at
|
|
FROM company_card_view_quota_usage
|
|
WHERE
|
|
organization_id = $1
|
|
AND last_seen_at > $2
|
|
`
|
|
|
|
type CountCompanyCardViewQuotaWindowParams struct {
|
|
OrganizationID pgtype.UUID
|
|
WindowStart pgtype.Timestamptz
|
|
}
|
|
|
|
type CountCompanyCardViewQuotaWindowRow struct {
|
|
UsageCount int64
|
|
EarliestAt interface{}
|
|
}
|
|
|
|
func (q *Queries) CountCompanyCardViewQuotaWindow(ctx context.Context, arg CountCompanyCardViewQuotaWindowParams) (CountCompanyCardViewQuotaWindowRow, error) {
|
|
row := q.db.QueryRow(ctx, countCompanyCardViewQuotaWindow, arg.OrganizationID, arg.WindowStart)
|
|
var i CountCompanyCardViewQuotaWindowRow
|
|
err := row.Scan(&i.UsageCount, &i.EarliestAt)
|
|
return i, err
|
|
}
|
|
|
|
const countCompanyInvitationQuotaWindow = `-- name: CountCompanyInvitationQuotaWindow :one
|
|
SELECT
|
|
count(*)::bigint AS usage_count,
|
|
min(reserved_at) AS earliest_at
|
|
FROM company_invitation_quota_usage
|
|
WHERE
|
|
organization_id = $1
|
|
AND reserved_at > $2
|
|
`
|
|
|
|
type CountCompanyInvitationQuotaWindowParams struct {
|
|
OrganizationID pgtype.UUID
|
|
WindowStart pgtype.Timestamptz
|
|
}
|
|
|
|
type CountCompanyInvitationQuotaWindowRow struct {
|
|
UsageCount int64
|
|
EarliestAt interface{}
|
|
}
|
|
|
|
func (q *Queries) CountCompanyInvitationQuotaWindow(ctx context.Context, arg CountCompanyInvitationQuotaWindowParams) (CountCompanyInvitationQuotaWindowRow, error) {
|
|
row := q.db.QueryRow(ctx, countCompanyInvitationQuotaWindow, arg.OrganizationID, arg.WindowStart)
|
|
var i CountCompanyInvitationQuotaWindowRow
|
|
err := row.Scan(&i.UsageCount, &i.EarliestAt)
|
|
return i, err
|
|
}
|
|
|
|
const deleteExpiredCompanyCardViewQuotaUsage = `-- name: DeleteExpiredCompanyCardViewQuotaUsage :execrows
|
|
WITH expired AS (
|
|
SELECT quota_usage.organization_id, quota_usage.candidate_id
|
|
FROM company_card_view_quota_usage AS quota_usage
|
|
WHERE
|
|
quota_usage.organization_id = $1
|
|
AND quota_usage.last_seen_at <= $2
|
|
ORDER BY quota_usage.last_seen_at, quota_usage.candidate_id
|
|
LIMIT $3::integer
|
|
)
|
|
DELETE FROM company_card_view_quota_usage AS usage
|
|
USING expired
|
|
WHERE
|
|
usage.organization_id = expired.organization_id
|
|
AND usage.candidate_id = expired.candidate_id
|
|
`
|
|
|
|
type DeleteExpiredCompanyCardViewQuotaUsageParams struct {
|
|
OrganizationID pgtype.UUID
|
|
WindowStart pgtype.Timestamptz
|
|
RowLimit int32
|
|
}
|
|
|
|
func (q *Queries) DeleteExpiredCompanyCardViewQuotaUsage(ctx context.Context, arg DeleteExpiredCompanyCardViewQuotaUsageParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, deleteExpiredCompanyCardViewQuotaUsage, arg.OrganizationID, arg.WindowStart, arg.RowLimit)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const findCompanyCardViewQuotaUsage = `-- name: FindCompanyCardViewQuotaUsage :one
|
|
SELECT last_seen_at
|
|
FROM company_card_view_quota_usage
|
|
WHERE
|
|
organization_id = $1
|
|
AND candidate_id = $2
|
|
FOR UPDATE
|
|
`
|
|
|
|
type FindCompanyCardViewQuotaUsageParams struct {
|
|
OrganizationID pgtype.UUID
|
|
CandidateID pgtype.UUID
|
|
}
|
|
|
|
func (q *Queries) FindCompanyCardViewQuotaUsage(ctx context.Context, arg FindCompanyCardViewQuotaUsageParams) (pgtype.Timestamptz, error) {
|
|
row := q.db.QueryRow(ctx, findCompanyCardViewQuotaUsage, arg.OrganizationID, arg.CandidateID)
|
|
var last_seen_at pgtype.Timestamptz
|
|
err := row.Scan(&last_seen_at)
|
|
return last_seen_at, err
|
|
}
|
|
|
|
const findCompanyInvitationQuotaUsage = `-- name: FindCompanyInvitationQuotaUsage :one
|
|
SELECT invitation_id
|
|
FROM company_invitation_quota_usage
|
|
WHERE
|
|
organization_id = $1
|
|
AND invitation_id = $2
|
|
FOR UPDATE
|
|
`
|
|
|
|
type FindCompanyInvitationQuotaUsageParams struct {
|
|
OrganizationID pgtype.UUID
|
|
InvitationID pgtype.UUID
|
|
}
|
|
|
|
func (q *Queries) FindCompanyInvitationQuotaUsage(ctx context.Context, arg FindCompanyInvitationQuotaUsageParams) (pgtype.UUID, error) {
|
|
row := q.db.QueryRow(ctx, findCompanyInvitationQuotaUsage, arg.OrganizationID, arg.InvitationID)
|
|
var invitation_id pgtype.UUID
|
|
err := row.Scan(&invitation_id)
|
|
return invitation_id, err
|
|
}
|
|
|
|
const insertCompanyInvitationQuotaUsage = `-- name: InsertCompanyInvitationQuotaUsage :exec
|
|
INSERT INTO company_invitation_quota_usage (
|
|
organization_id,
|
|
invitation_id,
|
|
reserved_at,
|
|
policy_version_id,
|
|
verification_level,
|
|
verification_basis,
|
|
verification_changed_at,
|
|
quota_tier
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8
|
|
)
|
|
`
|
|
|
|
type InsertCompanyInvitationQuotaUsageParams struct {
|
|
OrganizationID pgtype.UUID
|
|
InvitationID pgtype.UUID
|
|
ReservedAt pgtype.Timestamptz
|
|
PolicyVersionID pgtype.UUID
|
|
VerificationLevel string
|
|
VerificationBasis string
|
|
VerificationChangedAt pgtype.Timestamptz
|
|
QuotaTier string
|
|
}
|
|
|
|
func (q *Queries) InsertCompanyInvitationQuotaUsage(ctx context.Context, arg InsertCompanyInvitationQuotaUsageParams) error {
|
|
_, err := q.db.Exec(ctx, insertCompanyInvitationQuotaUsage,
|
|
arg.OrganizationID,
|
|
arg.InvitationID,
|
|
arg.ReservedAt,
|
|
arg.PolicyVersionID,
|
|
arg.VerificationLevel,
|
|
arg.VerificationBasis,
|
|
arg.VerificationChangedAt,
|
|
arg.QuotaTier,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const lockCompanyQuotaOrganization = `-- name: LockCompanyQuotaOrganization :one
|
|
|
|
SELECT
|
|
id,
|
|
verification_level,
|
|
verification_basis,
|
|
verification_changed_at
|
|
FROM organizations
|
|
WHERE id = $1
|
|
FOR UPDATE
|
|
`
|
|
|
|
type LockCompanyQuotaOrganizationRow struct {
|
|
ID pgtype.UUID
|
|
VerificationLevel string
|
|
VerificationBasis string
|
|
VerificationChangedAt pgtype.Timestamptz
|
|
}
|
|
|
|
// Writers lock the organization first, then invitation/card-view state, and
|
|
// finally usage rows. The organization lock serializes quota decisions for
|
|
// the tenant and makes the subsequent count and insert atomic.
|
|
func (q *Queries) LockCompanyQuotaOrganization(ctx context.Context, organizationID pgtype.UUID) (LockCompanyQuotaOrganizationRow, error) {
|
|
row := q.db.QueryRow(ctx, lockCompanyQuotaOrganization, organizationID)
|
|
var i LockCompanyQuotaOrganizationRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.VerificationLevel,
|
|
&i.VerificationBasis,
|
|
&i.VerificationChangedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const refreshCompanyCardViewQuotaUsage = `-- name: RefreshCompanyCardViewQuotaUsage :execrows
|
|
UPDATE company_card_view_quota_usage
|
|
SET
|
|
last_seen_at = greatest(last_seen_at, $1),
|
|
policy_version_id = $2,
|
|
verification_level = $3,
|
|
verification_basis = $4,
|
|
verification_changed_at = $5,
|
|
quota_tier = $6
|
|
WHERE
|
|
organization_id = $7
|
|
AND candidate_id = $8
|
|
AND last_seen_at > $9
|
|
`
|
|
|
|
type RefreshCompanyCardViewQuotaUsageParams struct {
|
|
LastSeenAt pgtype.Timestamptz
|
|
PolicyVersionID pgtype.UUID
|
|
VerificationLevel string
|
|
VerificationBasis string
|
|
VerificationChangedAt pgtype.Timestamptz
|
|
QuotaTier string
|
|
OrganizationID pgtype.UUID
|
|
CandidateID pgtype.UUID
|
|
WindowStart pgtype.Timestamptz
|
|
}
|
|
|
|
func (q *Queries) RefreshCompanyCardViewQuotaUsage(ctx context.Context, arg RefreshCompanyCardViewQuotaUsageParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, refreshCompanyCardViewQuotaUsage,
|
|
arg.LastSeenAt,
|
|
arg.PolicyVersionID,
|
|
arg.VerificationLevel,
|
|
arg.VerificationBasis,
|
|
arg.VerificationChangedAt,
|
|
arg.QuotaTier,
|
|
arg.OrganizationID,
|
|
arg.CandidateID,
|
|
arg.WindowStart,
|
|
)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const saveCompanyCardViewQuotaUsage = `-- name: SaveCompanyCardViewQuotaUsage :exec
|
|
INSERT INTO company_card_view_quota_usage (
|
|
organization_id,
|
|
candidate_id,
|
|
last_seen_at,
|
|
policy_version_id,
|
|
verification_level,
|
|
verification_basis,
|
|
verification_changed_at,
|
|
quota_tier
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8
|
|
)
|
|
ON CONFLICT (organization_id, candidate_id)
|
|
DO UPDATE SET
|
|
last_seen_at = greatest(
|
|
company_card_view_quota_usage.last_seen_at,
|
|
EXCLUDED.last_seen_at
|
|
),
|
|
policy_version_id = EXCLUDED.policy_version_id,
|
|
verification_level = EXCLUDED.verification_level,
|
|
verification_basis = EXCLUDED.verification_basis,
|
|
verification_changed_at = EXCLUDED.verification_changed_at,
|
|
quota_tier = EXCLUDED.quota_tier
|
|
`
|
|
|
|
type SaveCompanyCardViewQuotaUsageParams struct {
|
|
OrganizationID pgtype.UUID
|
|
CandidateID pgtype.UUID
|
|
LastSeenAt pgtype.Timestamptz
|
|
PolicyVersionID pgtype.UUID
|
|
VerificationLevel string
|
|
VerificationBasis string
|
|
VerificationChangedAt pgtype.Timestamptz
|
|
QuotaTier string
|
|
}
|
|
|
|
func (q *Queries) SaveCompanyCardViewQuotaUsage(ctx context.Context, arg SaveCompanyCardViewQuotaUsageParams) error {
|
|
_, err := q.db.Exec(ctx, saveCompanyCardViewQuotaUsage,
|
|
arg.OrganizationID,
|
|
arg.CandidateID,
|
|
arg.LastSeenAt,
|
|
arg.PolicyVersionID,
|
|
arg.VerificationLevel,
|
|
arg.VerificationBasis,
|
|
arg.VerificationChangedAt,
|
|
arg.QuotaTier,
|
|
)
|
|
return err
|
|
}
|