Files
OwnCord/Server/db/pgdbgen/invites.sql.go
T
J3vb 9116a880a3 feat(phase-bc): pass 5 — pgdbgen, postgres EventStore/PluginStore, plugin hub wiring, OTel stack, reconnect DB tier
- Generate Server/db/dbgen/{events,plugins}.sql.go and full Server/db/pgdbgen/ (//go:build postgres gated)
- Implement PostgresStore EventStore and PluginStore methods in store/postgres.go
- Wire plugin host_events.go EventSink into hub broadcast path (SetPluginEventSink)
- Wire host_commands.go slash-command dispatcher: chat_command V1 handler + hub.SetPluginRegistry
- Add handlers_command.go + handlers_command_test.go for plugin slash-command dispatch
- Add reconnect_db_test.go: TestReconnect_BufferMiss_FallsBackToDBTier (cold-tier DB replay)
- Add otel-up/otel-down Makefile targets; docker-compose.otel.yml + prometheus.dev.yml
- Update PHASE_BC_LOCAL_TODO.md: mark in-session items complete; document remaining network-blocked steps
- Minor fixes: channel_handler access-control, router plugin handler wiring, service span instrumentation
2026-04-06 22:48:59 +02:00

141 lines
3.5 KiB
Go

//go:build postgres
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: invites.sql
package pgdbgen
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const createInvite = `-- name: CreateInvite :exec
INSERT INTO invites (code, created_by, max_uses, expires_at) VALUES ($1, $2, $3, $4)
`
type CreateInviteParams struct {
Code string `json:"code"`
CreatedBy int64 `json:"createdBy"`
MaxUses *int32 `json:"maxUses"`
ExpiresAt pgtype.Timestamptz `json:"expiresAt"`
}
// PostgreSQL variants of the sqlite invites queries.
// The expiry check uses native timestamp comparison instead of sqlite's
// strftime('%s', …) trick.
func (q *Queries) CreateInvite(ctx context.Context, arg CreateInviteParams) error {
_, err := q.db.Exec(ctx, createInvite,
arg.Code,
arg.CreatedBy,
arg.MaxUses,
arg.ExpiresAt,
)
return err
}
const getInvite = `-- name: GetInvite :one
SELECT id, code, created_by, max_uses, use_count, expires_at, revoked, created_at
FROM invites WHERE code = $1
`
type GetInviteRow struct {
ID int64 `json:"id"`
Code string `json:"code"`
CreatedBy int64 `json:"createdBy"`
MaxUses *int32 `json:"maxUses"`
UseCount int32 `json:"useCount"`
ExpiresAt pgtype.Timestamptz `json:"expiresAt"`
Revoked bool `json:"revoked"`
CreatedAt pgtype.Timestamptz `json:"createdAt"`
}
func (q *Queries) GetInvite(ctx context.Context, code string) (GetInviteRow, error) {
row := q.db.QueryRow(ctx, getInvite, code)
var i GetInviteRow
err := row.Scan(
&i.ID,
&i.Code,
&i.CreatedBy,
&i.MaxUses,
&i.UseCount,
&i.ExpiresAt,
&i.Revoked,
&i.CreatedAt,
)
return i, err
}
const listInvites = `-- name: ListInvites :many
SELECT id, code, created_by, max_uses, use_count, expires_at, revoked, created_at
FROM invites ORDER BY created_at DESC LIMIT 200
`
type ListInvitesRow struct {
ID int64 `json:"id"`
Code string `json:"code"`
CreatedBy int64 `json:"createdBy"`
MaxUses *int32 `json:"maxUses"`
UseCount int32 `json:"useCount"`
ExpiresAt pgtype.Timestamptz `json:"expiresAt"`
Revoked bool `json:"revoked"`
CreatedAt pgtype.Timestamptz `json:"createdAt"`
}
func (q *Queries) ListInvites(ctx context.Context) ([]ListInvitesRow, error) {
rows, err := q.db.Query(ctx, listInvites)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListInvitesRow{}
for rows.Next() {
var i ListInvitesRow
if err := rows.Scan(
&i.ID,
&i.Code,
&i.CreatedBy,
&i.MaxUses,
&i.UseCount,
&i.ExpiresAt,
&i.Revoked,
&i.CreatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const revokeInvite = `-- name: RevokeInvite :exec
UPDATE invites SET revoked = TRUE WHERE code = $1
`
func (q *Queries) RevokeInvite(ctx context.Context, code string) error {
_, err := q.db.Exec(ctx, revokeInvite, code)
return err
}
const useInviteAtomic = `-- name: UseInviteAtomic :execrows
UPDATE invites SET use_count = use_count + 1
WHERE code = $1 AND revoked = FALSE
AND (max_uses IS NULL OR use_count < max_uses)
AND (expires_at IS NULL OR expires_at > NOW())
`
func (q *Queries) UseInviteAtomic(ctx context.Context, code string) (int64, error) {
result, err := q.db.Exec(ctx, useInviteAtomic, code)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}