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

215 lines
4.4 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: policy.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const getEffectivePolicyVersion = `-- name: GetEffectivePolicyVersion :one
SELECT
id,
policy_key,
version,
kind,
effective_at,
author,
document,
document_sha256,
created_at
FROM policy_versions
WHERE
policy_key = $1
AND effective_at <= $2
ORDER BY version DESC
LIMIT 1
`
type GetEffectivePolicyVersionParams struct {
PolicyKey string
At pgtype.Timestamptz
}
// Among the versions of a family already effective at a time, the newest
// publication wins. A version scheduled for later therefore never undoes a
// version published after it. The unique (policy_key, version) index serves
// the backward scan.
func (q *Queries) GetEffectivePolicyVersion(ctx context.Context, arg GetEffectivePolicyVersionParams) (PolicyVersion, error) {
row := q.db.QueryRow(ctx, getEffectivePolicyVersion, arg.PolicyKey, arg.At)
var i PolicyVersion
err := row.Scan(
&i.ID,
&i.PolicyKey,
&i.Version,
&i.Kind,
&i.EffectiveAt,
&i.Author,
&i.Document,
&i.DocumentSha256,
&i.CreatedAt,
)
return i, err
}
const getLatestPolicyVersion = `-- name: GetLatestPolicyVersion :one
SELECT
id,
policy_key,
version,
kind,
effective_at,
author,
document,
document_sha256,
created_at
FROM policy_versions
WHERE policy_key = $1
ORDER BY version DESC
LIMIT 1
`
func (q *Queries) GetLatestPolicyVersion(ctx context.Context, policyKey string) (PolicyVersion, error) {
row := q.db.QueryRow(ctx, getLatestPolicyVersion, policyKey)
var i PolicyVersion
err := row.Scan(
&i.ID,
&i.PolicyKey,
&i.Version,
&i.Kind,
&i.EffectiveAt,
&i.Author,
&i.Document,
&i.DocumentSha256,
&i.CreatedAt,
)
return i, err
}
const getPolicyVersionByID = `-- name: GetPolicyVersionByID :one
SELECT
id,
policy_key,
version,
kind,
effective_at,
author,
document,
document_sha256,
created_at
FROM policy_versions
WHERE id = $1
`
func (q *Queries) GetPolicyVersionByID(ctx context.Context, id pgtype.UUID) (PolicyVersion, error) {
row := q.db.QueryRow(ctx, getPolicyVersionByID, id)
var i PolicyVersion
err := row.Scan(
&i.ID,
&i.PolicyKey,
&i.Version,
&i.Kind,
&i.EffectiveAt,
&i.Author,
&i.Document,
&i.DocumentSha256,
&i.CreatedAt,
)
return i, err
}
const insertPolicyVersion = `-- name: InsertPolicyVersion :one
INSERT INTO policy_versions (
id,
policy_key,
version,
kind,
effective_at,
author,
document,
document_sha256
) VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8
)
ON CONFLICT DO NOTHING
RETURNING
id,
policy_key,
version,
kind,
effective_at,
author,
document,
document_sha256,
created_at
`
type InsertPolicyVersionParams struct {
ID pgtype.UUID
PolicyKey string
Version int32
Kind string
EffectiveAt pgtype.Timestamptz
Author string
Document []byte
DocumentSha256 []byte
}
// Stores a version and returns the stored row with the publication time and
// effective time set by the stamp trigger. A taken ID or version number
// returns no row instead of an error, so a conflict does not abort the
// surrounding transaction. created_at is never taken from the caller, and a
// NULL effective_at means "at publication".
func (q *Queries) InsertPolicyVersion(ctx context.Context, arg InsertPolicyVersionParams) (PolicyVersion, error) {
row := q.db.QueryRow(ctx, insertPolicyVersion,
arg.ID,
arg.PolicyKey,
arg.Version,
arg.Kind,
arg.EffectiveAt,
arg.Author,
arg.Document,
arg.DocumentSha256,
)
var i PolicyVersion
err := row.Scan(
&i.ID,
&i.PolicyKey,
&i.Version,
&i.Kind,
&i.EffectiveAt,
&i.Author,
&i.Document,
&i.DocumentSha256,
&i.CreatedAt,
)
return i, err
}
const policyVersionExists = `-- name: PolicyVersionExists :one
SELECT exists(
SELECT 1 FROM policy_versions
WHERE policy_key = $1
) AS present
`
// Reports whether a family has any version without reading a document, so a
// caller that only needs presence never depends on decoding.
func (q *Queries) PolicyVersionExists(ctx context.Context, policyKey string) (bool, error) {
row := q.db.QueryRow(ctx, policyVersionExists, policyKey)
var present bool
err := row.Scan(&present)
return present, err
}