162 lines
4.8 KiB
Go
162 lines
4.8 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
|
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: providers.sql
|
|
|
|
package integration
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const listPlatformResourceKeys = `-- name: ListPlatformResourceKeys :many
|
|
SELECT resource_key FROM core.resource_keys WHERE provider IS NULL ORDER BY resource_key
|
|
`
|
|
|
|
// Platform-owned (unprefixed) resource keys, for the provider-key hygiene
|
|
// nesting check.
|
|
func (q *Queries) ListPlatformResourceKeys(ctx context.Context) ([]string, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPlatformResourceKeys)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []string{}
|
|
for rows.Next() {
|
|
var resource_key string
|
|
if err := rows.Scan(&resource_key); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, resource_key)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listProviders = `-- name: ListProviders :many
|
|
SELECT provider, provider_kind, display_name, operator_surface_path, status, created_at, updated_at, suspended_at, retired_at FROM core.providers ORDER BY provider
|
|
`
|
|
|
|
func (q *Queries) ListProviders(ctx context.Context) ([]Provider, error) {
|
|
rows, err := q.db.QueryContext(ctx, listProviders)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Provider{}
|
|
for rows.Next() {
|
|
var i Provider
|
|
if err := rows.Scan(
|
|
&i.Provider,
|
|
&i.ProviderKind,
|
|
&i.DisplayName,
|
|
&i.OperatorSurfacePath,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.SuspendedAt,
|
|
&i.RetiredAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const setResourceKeyProvider = `-- name: SetResourceKeyProvider :one
|
|
UPDATE core.resource_keys
|
|
SET provider = $2,
|
|
recipient = $3,
|
|
over_limit_behavior = $4,
|
|
over_limit_consequence = $5
|
|
WHERE resource_key = $1
|
|
RETURNING (OLD.provider IS DISTINCT FROM NEW.provider
|
|
OR OLD.recipient IS DISTINCT FROM NEW.recipient)::boolean AS changed
|
|
`
|
|
|
|
type SetResourceKeyProviderParams struct {
|
|
ResourceKey string `json:"resource_key"`
|
|
Provider sql.NullString `json:"provider"`
|
|
Recipient sql.NullString `json:"recipient"`
|
|
OverLimitBehavior string `json:"over_limit_behavior"`
|
|
OverLimitConsequence sql.NullString `json:"over_limit_consequence"`
|
|
}
|
|
|
|
// Stamp provider ownership, the declared recipient and the over-limit pair on
|
|
// a resource key in one write (cross-schema write, enabled by the
|
|
// resource_keys.provider FK + this package's core_writer grant on the core
|
|
// schema). Returns whether the stamp changed the key's provider or recipient,
|
|
// the two values that decide which records carry the key, so registration can
|
|
// re-approve the provider's connection. No row (sql.ErrNoRows) means the
|
|
// manifest names a key that does not exist.
|
|
func (q *Queries) SetResourceKeyProvider(ctx context.Context, arg SetResourceKeyProviderParams) (bool, error) {
|
|
row := q.db.QueryRowContext(ctx, setResourceKeyProvider,
|
|
arg.ResourceKey,
|
|
arg.Provider,
|
|
arg.Recipient,
|
|
arg.OverLimitBehavior,
|
|
arg.OverLimitConsequence,
|
|
)
|
|
var changed bool
|
|
err := row.Scan(&changed)
|
|
return changed, err
|
|
}
|
|
|
|
const upsertProvider = `-- name: UpsertProvider :one
|
|
INSERT INTO core.providers (provider, provider_kind, display_name, operator_surface_path)
|
|
VALUES ($1, $2, $3, $4)
|
|
ON CONFLICT (provider) DO UPDATE
|
|
SET provider_kind = EXCLUDED.provider_kind,
|
|
display_name = EXCLUDED.display_name,
|
|
operator_surface_path = EXCLUDED.operator_surface_path,
|
|
updated_at = NOW()
|
|
RETURNING provider, provider_kind, display_name, operator_surface_path, status, created_at, updated_at, suspended_at, retired_at
|
|
`
|
|
|
|
type UpsertProviderParams struct {
|
|
Provider string `json:"provider"`
|
|
ProviderKind string `json:"provider_kind"`
|
|
DisplayName string `json:"display_name"`
|
|
OperatorSurfacePath sql.NullString `json:"operator_surface_path"`
|
|
}
|
|
|
|
// Boot-time capability registration. On re-registration, capability fields
|
|
// (kind, display_name) are refreshed; operational `status` is preserved.
|
|
func (q *Queries) UpsertProvider(ctx context.Context, arg UpsertProviderParams) (Provider, error) {
|
|
row := q.db.QueryRowContext(ctx, upsertProvider,
|
|
arg.Provider,
|
|
arg.ProviderKind,
|
|
arg.DisplayName,
|
|
arg.OperatorSurfacePath,
|
|
)
|
|
var i Provider
|
|
err := row.Scan(
|
|
&i.Provider,
|
|
&i.ProviderKind,
|
|
&i.DisplayName,
|
|
&i.OperatorSurfacePath,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.SuspendedAt,
|
|
&i.RetiredAt,
|
|
)
|
|
return i, err
|
|
}
|