Documentation
¶
Overview ¶
Package sqlite implements the reference SQLite store for the open-source core: the request log, budget ledger, settings, and a static model-price book. It deliberately migrates only the core tables — request_logs, model_prices, settings — never any enterprise table (tenants, api_keys, users, incidents, alert configs). Those belong to the enterprise module, which keeps its own handle and adapts to the core seams.
GORM and the pure-Go glebarez/sqlite driver are confined to this package (and its tests) per the core dependency rule.
Index ¶
- Constants
- type DB
- func (d *DB) Close() error
- func (d *DB) GetSettings(ctx context.Context) (proxy.SettingsRow, error)
- func (d *DB) ListModelPrices(ctx context.Context) ([]PriceRow, error)
- func (d *DB) LogRequest(ctx context.Context, r proxy.RequestRecord) error
- func (d *DB) SeedModelPrices(ctx context.Context, rows []PriceRow) error
- func (d *DB) SumActualCostForKeySince(ctx context.Context, keyID string, since int64) (int64, error)
- func (d *DB) SumActualCostSince(ctx context.Context, since int64) (int64, error)
- func (d *DB) UpdateSettings(ctx context.Context, s proxy.SettingsRow) error
- type PriceRow
Constants ¶
const ( PriceSourceSeed = "seed" PriceSourceManual = "manual" PriceSourceSync = "sync" )
Source values for the model_prices.source column.
const DefaultLoopThreshold = 2
DefaultLoopThreshold mirrors the detector's repeat-threshold default.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB wraps the gorm handle and serializes access. Writes and reads are serialized through a single mutex, and the SQLite handle is pinned to one connection so the connection-scoped WAL pragmas apply to every query.
func Open ¶
Open opens (creating if needed) the SQLite database at path, applies WAL pragmas, and migrates only the core tables. It creates the parent directory if it does not exist.
func (*DB) GetSettings ¶
GetSettings implements proxy.SettingsStore, seeding the defaults on first access so the table always holds exactly one row.
func (*DB) ListModelPrices ¶
ListModelPrices returns every price row, ordered by model case-insensitively.
func (*DB) LogRequest ¶
LogRequest implements proxy.RequestLogStore by persisting one request row.
func (*DB) SeedModelPrices ¶
SeedModelPrices inserts the static price rows with INSERT OR IGNORE semantics on the model key: an existing row is never overwritten. It is the core equivalent of the enterprise boot seeding, fed from the static config/pricing.json table.
func (*DB) SumActualCostForKeySince ¶
func (d *DB) SumActualCostForKeySince(ctx context.Context, keyID string, since int64) (int64, error)
SumActualCostForKeySince implements proxy.BudgetLedger: the sum of actual cost for one caller's requests at or after since. The empty keyID selects the anonymous/legacy bucket.
func (*DB) SumActualCostSince ¶
SumActualCostSince implements proxy.BudgetLedger: the sum of actual (non-loop-blocked) cost at or after since, across every caller.
func (*DB) UpdateSettings ¶
UpdateSettings implements proxy.SettingsStore by upserting the single row onto id = 1.
type PriceRow ¶
type PriceRow struct {
Model string
Provider string
InputMicroUSD int64 // µUSD per 1M input (prompt) tokens
OutputMicroUSD int64 // µUSD per 1M output (completion) tokens
Source string
}
PriceRow is the public form of one model_prices row, for seeding from the static config/pricing.json table and for listing.