Files
Mediarr/database/query.sql.go
T
2026-11-13 21:49:09 +01:00

1022 lines
23 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: query.sql
package database
import (
"context"
"database/sql"
"mediarr/ident"
)
const createAccount = `-- name: CreateAccount :one
INSERT INTO account (
principal_id,
login,
login_key,
password_hash,
password_changed_at,
must_change_password,
state,
failed_attempts,
locked_until,
last_login_at,
created_at
) VALUES (
?1,
?2,
?3,
?4,
?5,
?6,
?7,
?8,
?9,
?10,
?11
)
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
`
type CreateAccountParams struct {
PrincipalID ident.UUID
Login string
LoginKey string
PasswordHash sql.NullString
PasswordChangedAt sql.NullInt64
MustChangePassword int64
State string
FailedAttempts int64
LockedUntil sql.NullInt64
LastLoginAt sql.NullInt64
CreatedAt int64
}
// ============================================================================
// account
// ============================================================================
func (q *Queries) CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error) {
row := q.db.QueryRowContext(ctx, createAccount,
arg.PrincipalID,
arg.Login,
arg.LoginKey,
arg.PasswordHash,
arg.PasswordChangedAt,
arg.MustChangePassword,
arg.State,
arg.FailedAttempts,
arg.LockedUntil,
arg.LastLoginAt,
arg.CreatedAt,
)
var i Account
err := row.Scan(
&i.PrincipalID,
&i.Login,
&i.LoginKey,
&i.PasswordHash,
&i.PasswordChangedAt,
&i.MustChangePassword,
&i.State,
&i.FailedAttempts,
&i.LockedUntil,
&i.LastLoginAt,
&i.CreatedAt,
)
return i, err
}
const createMembership = `-- name: CreateMembership :one
INSERT INTO membership (
group_id,
member_id,
role,
created_at
) VALUES (
?1,
?2,
?3,
?4
)
RETURNING group_id, member_id, role, created_at
`
type CreateMembershipParams struct {
GroupID ident.UUID
MemberID ident.UUID
Role string
CreatedAt int64
}
// ============================================================================
// membership
// ============================================================================
func (q *Queries) CreateMembership(ctx context.Context, arg CreateMembershipParams) (Membership, error) {
row := q.db.QueryRowContext(ctx, createMembership,
arg.GroupID,
arg.MemberID,
arg.Role,
arg.CreatedAt,
)
var i Membership
err := row.Scan(
&i.GroupID,
&i.MemberID,
&i.Role,
&i.CreatedAt,
)
return i, err
}
const createPrincipal = `-- name: CreatePrincipal :one
INSERT INTO principal (
id,
kind,
name,
public_key,
status,
successor_id,
created_at,
disabled_at
) VALUES (
?1,
?2,
?3,
?4,
?5,
?6,
?7,
?8
)
RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at
`
type CreatePrincipalParams struct {
ID ident.UUID
Kind string
Name string
PublicKey []byte
Status string
SuccessorID *ident.UUID
CreatedAt int64
DisabledAt sql.NullInt64
}
// ============================================================================
// principal
// ============================================================================
func (q *Queries) CreatePrincipal(ctx context.Context, arg CreatePrincipalParams) (Principal, error) {
row := q.db.QueryRowContext(ctx, createPrincipal,
arg.ID,
arg.Kind,
arg.Name,
arg.PublicKey,
arg.Status,
arg.SuccessorID,
arg.CreatedAt,
arg.DisabledAt,
)
var i Principal
err := row.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
)
return i, err
}
const deleteAccount = `-- name: DeleteAccount :exec
DELETE FROM account
WHERE principal_id = ?1
`
func (q *Queries) DeleteAccount(ctx context.Context, principalID ident.UUID) error {
_, err := q.db.ExecContext(ctx, deleteAccount, principalID)
return err
}
const deleteMembership = `-- name: DeleteMembership :exec
DELETE FROM membership
WHERE group_id = ?1
AND member_id = ?2
`
type DeleteMembershipParams struct {
GroupID ident.UUID
MemberID ident.UUID
}
func (q *Queries) DeleteMembership(ctx context.Context, arg DeleteMembershipParams) error {
_, err := q.db.ExecContext(ctx, deleteMembership, arg.GroupID, arg.MemberID)
return err
}
const deletePrincipal = `-- name: DeletePrincipal :exec
DELETE FROM principal
WHERE id = ?1
`
func (q *Queries) DeletePrincipal(ctx context.Context, id ident.UUID) error {
_, err := q.db.ExecContext(ctx, deletePrincipal, id)
return err
}
const getAccount = `-- name: GetAccount :one
SELECT principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
FROM account
WHERE principal_id = ?1
`
func (q *Queries) GetAccount(ctx context.Context, principalID ident.UUID) (Account, error) {
row := q.db.QueryRowContext(ctx, getAccount, principalID)
var i Account
err := row.Scan(
&i.PrincipalID,
&i.Login,
&i.LoginKey,
&i.PasswordHash,
&i.PasswordChangedAt,
&i.MustChangePassword,
&i.State,
&i.FailedAttempts,
&i.LockedUntil,
&i.LastLoginAt,
&i.CreatedAt,
)
return i, err
}
const getAccountByLoginKey = `-- name: GetAccountByLoginKey :one
SELECT principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
FROM account
WHERE login_key = ?1
`
func (q *Queries) GetAccountByLoginKey(ctx context.Context, loginKey string) (Account, error) {
row := q.db.QueryRowContext(ctx, getAccountByLoginKey, loginKey)
var i Account
err := row.Scan(
&i.PrincipalID,
&i.Login,
&i.LoginKey,
&i.PasswordHash,
&i.PasswordChangedAt,
&i.MustChangePassword,
&i.State,
&i.FailedAttempts,
&i.LockedUntil,
&i.LastLoginAt,
&i.CreatedAt,
)
return i, err
}
const getClusterPrincipal = `-- name: GetClusterPrincipal :one
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
FROM principal
WHERE kind = 'cluster'
LIMIT 1
`
func (q *Queries) GetClusterPrincipal(ctx context.Context) (Principal, error) {
row := q.db.QueryRowContext(ctx, getClusterPrincipal)
var i Principal
err := row.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
)
return i, err
}
const getMembership = `-- name: GetMembership :one
SELECT group_id, member_id, role, created_at
FROM membership
WHERE group_id = ?1
AND member_id = ?2
`
type GetMembershipParams struct {
GroupID ident.UUID
MemberID ident.UUID
}
func (q *Queries) GetMembership(ctx context.Context, arg GetMembershipParams) (Membership, error) {
row := q.db.QueryRowContext(ctx, getMembership, arg.GroupID, arg.MemberID)
var i Membership
err := row.Scan(
&i.GroupID,
&i.MemberID,
&i.Role,
&i.CreatedAt,
)
return i, err
}
const getPrincipal = `-- name: GetPrincipal :one
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
FROM principal
WHERE id = ?1
`
func (q *Queries) GetPrincipal(ctx context.Context, id ident.UUID) (Principal, error) {
row := q.db.QueryRowContext(ctx, getPrincipal, id)
var i Principal
err := row.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
)
return i, err
}
const getPrincipalByName = `-- name: GetPrincipalByName :one
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
FROM principal
WHERE name = ?1
`
func (q *Queries) GetPrincipalByName(ctx context.Context, name string) (Principal, error) {
row := q.db.QueryRowContext(ctx, getPrincipalByName, name)
var i Principal
err := row.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
)
return i, err
}
const getPrincipalByNameAndKind = `-- name: GetPrincipalByNameAndKind :one
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
FROM principal
WHERE kind = ?1
AND name = ?2
`
type GetPrincipalByNameAndKindParams struct {
Kind string
Name string
}
func (q *Queries) GetPrincipalByNameAndKind(ctx context.Context, arg GetPrincipalByNameAndKindParams) (Principal, error) {
row := q.db.QueryRowContext(ctx, getPrincipalByNameAndKind, arg.Kind, arg.Name)
var i Principal
err := row.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
)
return i, err
}
const incrementFailedAttempts = `-- name: IncrementFailedAttempts :one
UPDATE account
SET failed_attempts = failed_attempts + 1
WHERE principal_id = ?1
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
`
func (q *Queries) IncrementFailedAttempts(ctx context.Context, principalID ident.UUID) (Account, error) {
row := q.db.QueryRowContext(ctx, incrementFailedAttempts, principalID)
var i Account
err := row.Scan(
&i.PrincipalID,
&i.Login,
&i.LoginKey,
&i.PasswordHash,
&i.PasswordChangedAt,
&i.MustChangePassword,
&i.State,
&i.FailedAttempts,
&i.LockedUntil,
&i.LastLoginAt,
&i.CreatedAt,
)
return i, err
}
const listActivePrincipals = `-- name: ListActivePrincipals :many
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
FROM principal
WHERE status = 'active'
ORDER BY name
`
func (q *Queries) ListActivePrincipals(ctx context.Context) ([]Principal, error) {
rows, err := q.db.QueryContext(ctx, listActivePrincipals)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Principal
for rows.Next() {
var i Principal
if err := rows.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
); 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 listGroupMembers = `-- name: ListGroupMembers :many
SELECT p.id, p.kind, p.name, p.public_key, p.status, p.successor_id, p.created_at, p.disabled_at
FROM membership m
JOIN principal p ON p.id = m.member_id
WHERE m.group_id = ?1
ORDER BY p.name
`
func (q *Queries) ListGroupMembers(ctx context.Context, groupID ident.UUID) ([]Principal, error) {
rows, err := q.db.QueryContext(ctx, listGroupMembers, groupID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Principal
for rows.Next() {
var i Principal
if err := rows.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
); 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 listMemberGroups = `-- name: ListMemberGroups :many
SELECT p.id, p.kind, p.name, p.public_key, p.status, p.successor_id, p.created_at, p.disabled_at
FROM membership m
JOIN principal p ON p.id = m.group_id
WHERE m.member_id = ?1
ORDER BY p.name
`
func (q *Queries) ListMemberGroups(ctx context.Context, memberID ident.UUID) ([]Principal, error) {
rows, err := q.db.QueryContext(ctx, listMemberGroups, memberID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Principal
for rows.Next() {
var i Principal
if err := rows.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
); 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 listMembershipsByGroup = `-- name: ListMembershipsByGroup :many
SELECT group_id, member_id, role, created_at
FROM membership
WHERE group_id = ?1
ORDER BY created_at
`
func (q *Queries) ListMembershipsByGroup(ctx context.Context, groupID ident.UUID) ([]Membership, error) {
rows, err := q.db.QueryContext(ctx, listMembershipsByGroup, groupID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Membership
for rows.Next() {
var i Membership
if err := rows.Scan(
&i.GroupID,
&i.MemberID,
&i.Role,
&i.CreatedAt,
); 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 listMembershipsByMember = `-- name: ListMembershipsByMember :many
SELECT group_id, member_id, role, created_at
FROM membership
WHERE member_id = ?1
ORDER BY created_at
`
func (q *Queries) ListMembershipsByMember(ctx context.Context, memberID ident.UUID) ([]Membership, error) {
rows, err := q.db.QueryContext(ctx, listMembershipsByMember, memberID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Membership
for rows.Next() {
var i Membership
if err := rows.Scan(
&i.GroupID,
&i.MemberID,
&i.Role,
&i.CreatedAt,
); 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 listPrincipals = `-- name: ListPrincipals :many
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
FROM principal
ORDER BY name
`
func (q *Queries) ListPrincipals(ctx context.Context) ([]Principal, error) {
rows, err := q.db.QueryContext(ctx, listPrincipals)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Principal
for rows.Next() {
var i Principal
if err := rows.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
); 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 listPrincipalsByKind = `-- name: ListPrincipalsByKind :many
SELECT id, kind, name, public_key, status, successor_id, created_at, disabled_at
FROM principal
WHERE kind = ?1
ORDER BY name
`
func (q *Queries) ListPrincipalsByKind(ctx context.Context, kind string) ([]Principal, error) {
rows, err := q.db.QueryContext(ctx, listPrincipalsByKind, kind)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Principal
for rows.Next() {
var i Principal
if err := rows.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
); 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 lockAccount = `-- name: LockAccount :one
UPDATE account
SET state = 'locked',
locked_until = ?1
WHERE principal_id = ?2
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
`
type LockAccountParams struct {
LockedUntil sql.NullInt64
PrincipalID ident.UUID
}
func (q *Queries) LockAccount(ctx context.Context, arg LockAccountParams) (Account, error) {
row := q.db.QueryRowContext(ctx, lockAccount, arg.LockedUntil, arg.PrincipalID)
var i Account
err := row.Scan(
&i.PrincipalID,
&i.Login,
&i.LoginKey,
&i.PasswordHash,
&i.PasswordChangedAt,
&i.MustChangePassword,
&i.State,
&i.FailedAttempts,
&i.LockedUntil,
&i.LastLoginAt,
&i.CreatedAt,
)
return i, err
}
const recordLogin = `-- name: RecordLogin :one
UPDATE account
SET last_login_at = ?1,
failed_attempts = 0,
locked_until = NULL
WHERE principal_id = ?2
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
`
type RecordLoginParams struct {
LastLoginAt sql.NullInt64
PrincipalID ident.UUID
}
func (q *Queries) RecordLogin(ctx context.Context, arg RecordLoginParams) (Account, error) {
row := q.db.QueryRowContext(ctx, recordLogin, arg.LastLoginAt, arg.PrincipalID)
var i Account
err := row.Scan(
&i.PrincipalID,
&i.Login,
&i.LoginKey,
&i.PasswordHash,
&i.PasswordChangedAt,
&i.MustChangePassword,
&i.State,
&i.FailedAttempts,
&i.LockedUntil,
&i.LastLoginAt,
&i.CreatedAt,
)
return i, err
}
const resetFailedAttempts = `-- name: ResetFailedAttempts :one
UPDATE account
SET failed_attempts = 0,
locked_until = NULL
WHERE principal_id = ?1
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
`
func (q *Queries) ResetFailedAttempts(ctx context.Context, principalID ident.UUID) (Account, error) {
row := q.db.QueryRowContext(ctx, resetFailedAttempts, principalID)
var i Account
err := row.Scan(
&i.PrincipalID,
&i.Login,
&i.LoginKey,
&i.PasswordHash,
&i.PasswordChangedAt,
&i.MustChangePassword,
&i.State,
&i.FailedAttempts,
&i.LockedUntil,
&i.LastLoginAt,
&i.CreatedAt,
)
return i, err
}
const unlockAccount = `-- name: UnlockAccount :one
UPDATE account
SET state = 'active',
failed_attempts = 0,
locked_until = NULL
WHERE principal_id = ?1
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
`
func (q *Queries) UnlockAccount(ctx context.Context, principalID ident.UUID) (Account, error) {
row := q.db.QueryRowContext(ctx, unlockAccount, principalID)
var i Account
err := row.Scan(
&i.PrincipalID,
&i.Login,
&i.LoginKey,
&i.PasswordHash,
&i.PasswordChangedAt,
&i.MustChangePassword,
&i.State,
&i.FailedAttempts,
&i.LockedUntil,
&i.LastLoginAt,
&i.CreatedAt,
)
return i, err
}
const updateAccountState = `-- name: UpdateAccountState :one
UPDATE account
SET state = ?1
WHERE principal_id = ?2
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
`
type UpdateAccountStateParams struct {
State string
PrincipalID ident.UUID
}
func (q *Queries) UpdateAccountState(ctx context.Context, arg UpdateAccountStateParams) (Account, error) {
row := q.db.QueryRowContext(ctx, updateAccountState, arg.State, arg.PrincipalID)
var i Account
err := row.Scan(
&i.PrincipalID,
&i.Login,
&i.LoginKey,
&i.PasswordHash,
&i.PasswordChangedAt,
&i.MustChangePassword,
&i.State,
&i.FailedAttempts,
&i.LockedUntil,
&i.LastLoginAt,
&i.CreatedAt,
)
return i, err
}
const updateMembershipRole = `-- name: UpdateMembershipRole :one
UPDATE membership
SET role = ?1
WHERE group_id = ?2
AND member_id = ?3
RETURNING group_id, member_id, role, created_at
`
type UpdateMembershipRoleParams struct {
Role string
GroupID ident.UUID
MemberID ident.UUID
}
func (q *Queries) UpdateMembershipRole(ctx context.Context, arg UpdateMembershipRoleParams) (Membership, error) {
row := q.db.QueryRowContext(ctx, updateMembershipRole, arg.Role, arg.GroupID, arg.MemberID)
var i Membership
err := row.Scan(
&i.GroupID,
&i.MemberID,
&i.Role,
&i.CreatedAt,
)
return i, err
}
const updatePassword = `-- name: UpdatePassword :one
UPDATE account
SET password_hash = ?1,
password_changed_at = ?2,
must_change_password = 0,
failed_attempts = 0,
locked_until = NULL
WHERE principal_id = ?3
RETURNING principal_id, login, login_key, password_hash, password_changed_at, must_change_password, state, failed_attempts, locked_until, last_login_at, created_at
`
type UpdatePasswordParams struct {
PasswordHash sql.NullString
PasswordChangedAt sql.NullInt64
PrincipalID ident.UUID
}
func (q *Queries) UpdatePassword(ctx context.Context, arg UpdatePasswordParams) (Account, error) {
row := q.db.QueryRowContext(ctx, updatePassword, arg.PasswordHash, arg.PasswordChangedAt, arg.PrincipalID)
var i Account
err := row.Scan(
&i.PrincipalID,
&i.Login,
&i.LoginKey,
&i.PasswordHash,
&i.PasswordChangedAt,
&i.MustChangePassword,
&i.State,
&i.FailedAttempts,
&i.LockedUntil,
&i.LastLoginAt,
&i.CreatedAt,
)
return i, err
}
const updatePrincipalName = `-- name: UpdatePrincipalName :one
UPDATE principal
SET name = ?1
WHERE id = ?2
RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at
`
type UpdatePrincipalNameParams struct {
Name string
ID ident.UUID
}
func (q *Queries) UpdatePrincipalName(ctx context.Context, arg UpdatePrincipalNameParams) (Principal, error) {
row := q.db.QueryRowContext(ctx, updatePrincipalName, arg.Name, arg.ID)
var i Principal
err := row.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
)
return i, err
}
const updatePrincipalPublicKey = `-- name: UpdatePrincipalPublicKey :one
UPDATE principal
SET public_key = ?1
WHERE id = ?2
RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at
`
type UpdatePrincipalPublicKeyParams struct {
PublicKey []byte
ID ident.UUID
}
func (q *Queries) UpdatePrincipalPublicKey(ctx context.Context, arg UpdatePrincipalPublicKeyParams) (Principal, error) {
row := q.db.QueryRowContext(ctx, updatePrincipalPublicKey, arg.PublicKey, arg.ID)
var i Principal
err := row.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
)
return i, err
}
const updatePrincipalStatus = `-- name: UpdatePrincipalStatus :one
UPDATE principal
SET status = ?1,
disabled_at = ?2
WHERE id = ?3
RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at
`
type UpdatePrincipalStatusParams struct {
Status string
DisabledAt sql.NullInt64
ID ident.UUID
}
func (q *Queries) UpdatePrincipalStatus(ctx context.Context, arg UpdatePrincipalStatusParams) (Principal, error) {
row := q.db.QueryRowContext(ctx, updatePrincipalStatus, arg.Status, arg.DisabledAt, arg.ID)
var i Principal
err := row.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
)
return i, err
}
const updatePrincipalSuccessor = `-- name: UpdatePrincipalSuccessor :one
UPDATE principal
SET successor_id = ?1
WHERE id = ?2
RETURNING id, kind, name, public_key, status, successor_id, created_at, disabled_at
`
type UpdatePrincipalSuccessorParams struct {
SuccessorID *ident.UUID
ID ident.UUID
}
func (q *Queries) UpdatePrincipalSuccessor(ctx context.Context, arg UpdatePrincipalSuccessorParams) (Principal, error) {
row := q.db.QueryRowContext(ctx, updatePrincipalSuccessor, arg.SuccessorID, arg.ID)
var i Principal
err := row.Scan(
&i.ID,
&i.Kind,
&i.Name,
&i.PublicKey,
&i.Status,
&i.SuccessorID,
&i.CreatedAt,
&i.DisabledAt,
)
return i, err
}