mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-11-04 12:07:46 +00:00
* feat(db): five pgx pools with fixed session settings and Prometheus tracing * feat(guards): per-family observe/enforce guards with client slots, deadlines and a shadow budget * fix(guards): attribute only guard deadlines and classify like the handlers * feat(db): route API statements by sqlc name; class C always unnamed * feat(admin): statement statistics by sqlc name; create pg_stat_statements where allowed * fix(db): skip pg_stat_statements when no schema is creatable * feat(background): index health against post-rebuild baselines, Postgres activity, job and ingest metrics * feat: separate API, ingest and maintenance stores; guards on the public API; metrics listener * fix(db): keep ingest writes waiting, size the ingest pool to the host, tidy * test(db): give the statements probe a query id of its own
35 lines
1.3 KiB
Go
35 lines
1.3 KiB
Go
// Copyright 2026 Beacon Contributors
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
sqlc "github.com/MeshCore-Beacon/beacon-server/db/sqlc"
|
|
"github.com/jackc/pgx/v5"
|
|
"github.com/jackc/pgx/v5/pgconn"
|
|
)
|
|
|
|
// unnamedDBTX runs every statement as an unnamed prepared statement (pgx.QueryExecModeCacheDescribe):
|
|
// pgx caches only the description, never a named server-side statement, so Postgres cannot switch it
|
|
// to a generic plan after five executions. Test-only: test fixtures use it to mirror PlanRouter's
|
|
// class C path.
|
|
//
|
|
// Unnamed statements are planned with their values on every call under plan_cache_mode auto or
|
|
// force_custom_plan. force_generic_plan still makes them generic, so api_cached must never take
|
|
// these statements.
|
|
type unnamedDBTX struct{ sqlc.DBTX }
|
|
|
|
func (u unnamedDBTX) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error) {
|
|
return u.DBTX.Exec(ctx, sql, append([]any{pgx.QueryExecModeCacheDescribe}, args...)...)
|
|
}
|
|
|
|
func (u unnamedDBTX) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error) {
|
|
return u.DBTX.Query(ctx, sql, append([]any{pgx.QueryExecModeCacheDescribe}, args...)...)
|
|
}
|
|
|
|
func (u unnamedDBTX) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row {
|
|
return u.DBTX.QueryRow(ctx, sql, append([]any{pgx.QueryExecModeCacheDescribe}, args...)...)
|
|
}
|