Files
Memoh/internal/db/sqlc/models.sql.go
T
Acbox Liu 8d5c38f0e5 refactor: unify providers and models tables (#338)
* refactor: unify providers and models tables

- Rename `llm_providers` → `providers`, `llm_provider_oauth_tokens` → `provider_oauth_tokens`
- Remove `tts_providers` and `tts_models` tables; speech models now live in the unified `models` table with `type = 'speech'`
- Replace top-level `api_key`/`base_url` columns with a JSONB `config` field on `providers`
- Rename `llm_provider_id` → `provider_id` across all references
- Add `edge-speech` client type and `conf/providers/edge.yaml` default provider
- Create new read-only speech endpoints (`/speech-providers`, `/speech-models`) backed by filtered views of the unified tables
- Remove old TTS CRUD handlers; simplify speech page to read-only + test
- Update registry loader to skip malformed YAML files instead of failing entirely
- Fix YAML quoting for model names containing colons in openrouter.yaml
- Regenerate sqlc, swagger, and TypeScript SDK

* fix: exclude speech providers from providers list endpoint

ListProviders now filters out client_type matching '%-speech' so Edge
and future speech providers no longer appear on the Providers page.
ListSpeechProviders uses the same pattern match instead of hard-coding
'edge-speech'.

* fix: use explicit client_type list instead of LIKE pattern

Replace '%-speech' pattern with explicit IN ('edge-speech') for both
ListProviders (exclusion) and ListSpeechProviders (inclusion). New
speech client types must be added to both queries.

* fix: use EXECUTE for dynamic SQL in migrations referencing old schema

PL/pgSQL pre-validates column/table references in static SQL statements
inside DO blocks before evaluating IF/RETURN guards. This caused
migrations 0010-0061 to fail on fresh databases where the canonical
schema uses `providers`/`provider_id` instead of `llm_providers`/
`llm_provider_id`.

Wrap all SQL that references potentially non-existent old schema objects
(llm_providers, llm_provider_id, tts_providers, tts_models, etc.) in
EXECUTE strings so they are only parsed at runtime when actually reached.

* fix: revert canonical schema to use llm_providers for migration compatibility

The CI migrations workflow (up → down → up) failed because 0061 down
renames `providers` back to `llm_providers`, but 0001 down only dropped
`providers` — leaving `llm_providers` as a remnant. On the second
migrate up, 0010 found the stale `llm_providers` and tried to reference
`models.llm_provider_id` which no longer existed.

Revert 0001 canonical schema to use original names (llm_providers,
tts_providers, tts_models) so incremental migrations work naturally and
0061 handles the final rename. Remove EXECUTE wrappers and unnecessary
guards from migrations that now always operate on llm_providers.

* fix: icons

* fix: sync canonical schema with 0061 migration to fix sqlc column mismatch

0001_init.up.sql still used old names (llm_providers, llm_provider_id)
and included dropped tts_providers/tts_models tables. sqlc could not
parse the PL/pgSQL EXECUTE in migration 0061, so generated code retained
stale columns (input_modalities, supports_reasoning) causing runtime
"column does not exist" errors when adding models.

- Update 0001_init.up.sql to current schema (providers, provider_id,
  no tts tables, add provider_oauth_tokens)
- Use ALTER TABLE IF EXISTS in 0010/0041/0042 for backward compat
- Regenerate sqlc

* fix: guard all legacy migrations against fresh schema for CI compat

On fresh databases, 0001_init.up.sql creates providers/provider_id
(not llm_providers/llm_provider_id). Migrations 0013, 0041, 0046, 0047
referenced the old names without guards, causing CI migration failures.

- 0013: check llm_provider_id column exists before adding old constraint
- 0041: check llm_providers table exists before backfill/constraint DDL
- 0046: wrap CREATE TABLE in DO block with llm_providers existence check
- 0047: use ALTER TABLE IF EXISTS + DO block guard
2026-04-08 01:03:44 +08:00

1050 lines
24 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: models.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const countModels = `-- name: CountModels :one
SELECT COUNT(*) FROM models
`
func (q *Queries) CountModels(ctx context.Context) (int64, error) {
row := q.db.QueryRow(ctx, countModels)
var count int64
err := row.Scan(&count)
return count, err
}
const countModelsByType = `-- name: CountModelsByType :one
SELECT COUNT(*) FROM models WHERE type = $1
`
func (q *Queries) CountModelsByType(ctx context.Context, type_ string) (int64, error) {
row := q.db.QueryRow(ctx, countModelsByType, type_)
var count int64
err := row.Scan(&count)
return count, err
}
const countProviders = `-- name: CountProviders :one
SELECT COUNT(*) FROM providers
`
func (q *Queries) CountProviders(ctx context.Context) (int64, error) {
row := q.db.QueryRow(ctx, countProviders)
var count int64
err := row.Scan(&count)
return count, err
}
const createModel = `-- name: CreateModel :one
INSERT INTO models (model_id, name, provider_id, type, config)
VALUES (
$1,
$2,
$3,
$4,
$5
)
RETURNING id, model_id, name, provider_id, type, config, created_at, updated_at
`
type CreateModelParams struct {
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
}
func (q *Queries) CreateModel(ctx context.Context, arg CreateModelParams) (Model, error) {
row := q.db.QueryRow(ctx, createModel,
arg.ModelID,
arg.Name,
arg.ProviderID,
arg.Type,
arg.Config,
)
var i Model
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const createModelVariant = `-- name: CreateModelVariant :one
INSERT INTO model_variants (model_uuid, variant_id, weight, metadata)
VALUES (
$1,
$2,
$3,
$4
)
RETURNING id, model_uuid, variant_id, weight, metadata, created_at, updated_at
`
type CreateModelVariantParams struct {
ModelUuid pgtype.UUID `json:"model_uuid"`
VariantID string `json:"variant_id"`
Weight int32 `json:"weight"`
Metadata []byte `json:"metadata"`
}
func (q *Queries) CreateModelVariant(ctx context.Context, arg CreateModelVariantParams) (ModelVariant, error) {
row := q.db.QueryRow(ctx, createModelVariant,
arg.ModelUuid,
arg.VariantID,
arg.Weight,
arg.Metadata,
)
var i ModelVariant
err := row.Scan(
&i.ID,
&i.ModelUuid,
&i.VariantID,
&i.Weight,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const createProvider = `-- name: CreateProvider :one
INSERT INTO providers (name, client_type, icon, enable, config, metadata)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6
)
RETURNING id, name, client_type, icon, enable, config, metadata, created_at, updated_at
`
type CreateProviderParams struct {
Name string `json:"name"`
ClientType string `json:"client_type"`
Icon pgtype.Text `json:"icon"`
Enable bool `json:"enable"`
Config []byte `json:"config"`
Metadata []byte `json:"metadata"`
}
func (q *Queries) CreateProvider(ctx context.Context, arg CreateProviderParams) (Provider, error) {
row := q.db.QueryRow(ctx, createProvider,
arg.Name,
arg.ClientType,
arg.Icon,
arg.Enable,
arg.Config,
arg.Metadata,
)
var i Provider
err := row.Scan(
&i.ID,
&i.Name,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteModel = `-- name: DeleteModel :exec
DELETE FROM models WHERE id = $1
`
func (q *Queries) DeleteModel(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteModel, id)
return err
}
const deleteModelByModelID = `-- name: DeleteModelByModelID :exec
DELETE FROM models WHERE model_id = $1
`
func (q *Queries) DeleteModelByModelID(ctx context.Context, modelID string) error {
_, err := q.db.Exec(ctx, deleteModelByModelID, modelID)
return err
}
const deleteProvider = `-- name: DeleteProvider :exec
DELETE FROM providers WHERE id = $1
`
func (q *Queries) DeleteProvider(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteProvider, id)
return err
}
const getModelByID = `-- name: GetModelByID :one
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models WHERE id = $1
`
func (q *Queries) GetModelByID(ctx context.Context, id pgtype.UUID) (Model, error) {
row := q.db.QueryRow(ctx, getModelByID, id)
var i Model
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getModelByModelID = `-- name: GetModelByModelID :one
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models WHERE model_id = $1
`
func (q *Queries) GetModelByModelID(ctx context.Context, modelID string) (Model, error) {
row := q.db.QueryRow(ctx, getModelByModelID, modelID)
var i Model
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getModelByProviderAndModelID = `-- name: GetModelByProviderAndModelID :one
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE provider_id = $1
AND model_id = $2
LIMIT 1
`
type GetModelByProviderAndModelIDParams struct {
ProviderID pgtype.UUID `json:"provider_id"`
ModelID string `json:"model_id"`
}
func (q *Queries) GetModelByProviderAndModelID(ctx context.Context, arg GetModelByProviderAndModelIDParams) (Model, error) {
row := q.db.QueryRow(ctx, getModelByProviderAndModelID, arg.ProviderID, arg.ModelID)
var i Model
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getProviderByID = `-- name: GetProviderByID :one
SELECT id, name, client_type, icon, enable, config, metadata, created_at, updated_at FROM providers WHERE id = $1
`
func (q *Queries) GetProviderByID(ctx context.Context, id pgtype.UUID) (Provider, error) {
row := q.db.QueryRow(ctx, getProviderByID, id)
var i Provider
err := row.Scan(
&i.ID,
&i.Name,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getProviderByName = `-- name: GetProviderByName :one
SELECT id, name, client_type, icon, enable, config, metadata, created_at, updated_at FROM providers WHERE name = $1
`
func (q *Queries) GetProviderByName(ctx context.Context, name string) (Provider, error) {
row := q.db.QueryRow(ctx, getProviderByName, name)
var i Provider
err := row.Scan(
&i.ID,
&i.Name,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getSpeechModelWithProvider = `-- name: GetSpeechModelWithProvider :one
SELECT
m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at,
p.client_type AS provider_type
FROM models m
JOIN providers p ON p.id = m.provider_id
WHERE m.id = $1
AND m.type = 'speech'
`
type GetSpeechModelWithProviderRow struct {
ID pgtype.UUID `json:"id"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ProviderType string `json:"provider_type"`
}
func (q *Queries) GetSpeechModelWithProvider(ctx context.Context, id pgtype.UUID) (GetSpeechModelWithProviderRow, error) {
row := q.db.QueryRow(ctx, getSpeechModelWithProvider, id)
var i GetSpeechModelWithProviderRow
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.ProviderType,
)
return i, err
}
const listEnabledModels = `-- name: ListEnabledModels :many
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at
FROM models m
JOIN providers p ON m.provider_id = p.id
WHERE p.enable = true
ORDER BY m.created_at DESC
`
func (q *Queries) ListEnabledModels(ctx context.Context) ([]Model, error) {
rows, err := q.db.Query(ctx, listEnabledModels)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listEnabledModelsByProviderClientType = `-- name: ListEnabledModelsByProviderClientType :many
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at
FROM models m
JOIN providers p ON m.provider_id = p.id
WHERE p.enable = true
AND p.client_type = $1
ORDER BY m.created_at DESC
`
func (q *Queries) ListEnabledModelsByProviderClientType(ctx context.Context, clientType string) ([]Model, error) {
rows, err := q.db.Query(ctx, listEnabledModelsByProviderClientType, clientType)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listEnabledModelsByType = `-- name: ListEnabledModelsByType :many
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at
FROM models m
JOIN providers p ON m.provider_id = p.id
WHERE p.enable = true
AND m.type = $1
ORDER BY m.created_at DESC
`
func (q *Queries) ListEnabledModelsByType(ctx context.Context, type_ string) ([]Model, error) {
rows, err := q.db.Query(ctx, listEnabledModelsByType, type_)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listModelVariantsByModelUUID = `-- name: ListModelVariantsByModelUUID :many
SELECT id, model_uuid, variant_id, weight, metadata, created_at, updated_at FROM model_variants
WHERE model_uuid = $1
ORDER BY weight DESC, created_at DESC
`
func (q *Queries) ListModelVariantsByModelUUID(ctx context.Context, modelUuid pgtype.UUID) ([]ModelVariant, error) {
rows, err := q.db.Query(ctx, listModelVariantsByModelUUID, modelUuid)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ModelVariant
for rows.Next() {
var i ModelVariant
if err := rows.Scan(
&i.ID,
&i.ModelUuid,
&i.VariantID,
&i.Weight,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listModels = `-- name: ListModels :many
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
ORDER BY created_at DESC
`
func (q *Queries) ListModels(ctx context.Context) ([]Model, error) {
rows, err := q.db.Query(ctx, listModels)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listModelsByModelID = `-- name: ListModelsByModelID :many
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE model_id = $1
ORDER BY created_at DESC
`
func (q *Queries) ListModelsByModelID(ctx context.Context, modelID string) ([]Model, error) {
rows, err := q.db.Query(ctx, listModelsByModelID, modelID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listModelsByProviderClientType = `-- name: ListModelsByProviderClientType :many
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at
FROM models m
JOIN providers p ON m.provider_id = p.id
WHERE p.client_type = $1
ORDER BY m.created_at DESC
`
func (q *Queries) ListModelsByProviderClientType(ctx context.Context, clientType string) ([]Model, error) {
rows, err := q.db.Query(ctx, listModelsByProviderClientType, clientType)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listModelsByProviderID = `-- name: ListModelsByProviderID :many
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE provider_id = $1
ORDER BY created_at DESC
`
func (q *Queries) ListModelsByProviderID(ctx context.Context, providerID pgtype.UUID) ([]Model, error) {
rows, err := q.db.Query(ctx, listModelsByProviderID, providerID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listModelsByProviderIDAndType = `-- name: ListModelsByProviderIDAndType :many
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE provider_id = $1
AND type = $2
ORDER BY created_at DESC
`
type ListModelsByProviderIDAndTypeParams struct {
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
}
func (q *Queries) ListModelsByProviderIDAndType(ctx context.Context, arg ListModelsByProviderIDAndTypeParams) ([]Model, error) {
rows, err := q.db.Query(ctx, listModelsByProviderIDAndType, arg.ProviderID, arg.Type)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listModelsByType = `-- name: ListModelsByType :many
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE type = $1
ORDER BY created_at DESC
`
func (q *Queries) ListModelsByType(ctx context.Context, type_ string) ([]Model, error) {
rows, err := q.db.Query(ctx, listModelsByType, type_)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listProviders = `-- name: ListProviders :many
SELECT id, name, client_type, icon, enable, config, metadata, created_at, updated_at FROM providers
WHERE client_type NOT IN ('edge-speech')
ORDER BY created_at DESC
`
func (q *Queries) ListProviders(ctx context.Context) ([]Provider, error) {
rows, err := q.db.Query(ctx, listProviders)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Provider
for rows.Next() {
var i Provider
if err := rows.Scan(
&i.ID,
&i.Name,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listSpeechModels = `-- name: ListSpeechModels :many
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at,
p.client_type AS provider_type
FROM models m
JOIN providers p ON p.id = m.provider_id
WHERE m.type = 'speech'
ORDER BY m.created_at DESC
`
type ListSpeechModelsRow struct {
ID pgtype.UUID `json:"id"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ProviderType string `json:"provider_type"`
}
func (q *Queries) ListSpeechModels(ctx context.Context) ([]ListSpeechModelsRow, error) {
rows, err := q.db.Query(ctx, listSpeechModels)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListSpeechModelsRow
for rows.Next() {
var i ListSpeechModelsRow
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.ProviderType,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listSpeechModelsByProviderID = `-- name: ListSpeechModelsByProviderID :many
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE provider_id = $1
AND type = 'speech'
ORDER BY created_at DESC
`
func (q *Queries) ListSpeechModelsByProviderID(ctx context.Context, providerID pgtype.UUID) ([]Model, error) {
rows, err := q.db.Query(ctx, listSpeechModelsByProviderID, providerID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listSpeechProviders = `-- name: ListSpeechProviders :many
SELECT id, name, client_type, icon, enable, config, metadata, created_at, updated_at FROM providers
WHERE client_type IN ('edge-speech')
ORDER BY created_at DESC
`
func (q *Queries) ListSpeechProviders(ctx context.Context) ([]Provider, error) {
rows, err := q.db.Query(ctx, listSpeechProviders)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Provider
for rows.Next() {
var i Provider
if err := rows.Scan(
&i.ID,
&i.Name,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateModel = `-- name: UpdateModel :one
UPDATE models
SET
model_id = $1,
name = $2,
provider_id = $3,
type = $4,
config = $5,
updated_at = now()
WHERE id = $6
RETURNING id, model_id, name, provider_id, type, config, created_at, updated_at
`
type UpdateModelParams struct {
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) UpdateModel(ctx context.Context, arg UpdateModelParams) (Model, error) {
row := q.db.QueryRow(ctx, updateModel,
arg.ModelID,
arg.Name,
arg.ProviderID,
arg.Type,
arg.Config,
arg.ID,
)
var i Model
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const updateProvider = `-- name: UpdateProvider :one
UPDATE providers
SET
name = $1,
client_type = $2,
icon = $3,
enable = $4,
config = $5,
metadata = $6,
updated_at = now()
WHERE id = $7
RETURNING id, name, client_type, icon, enable, config, metadata, created_at, updated_at
`
type UpdateProviderParams struct {
Name string `json:"name"`
ClientType string `json:"client_type"`
Icon pgtype.Text `json:"icon"`
Enable bool `json:"enable"`
Config []byte `json:"config"`
Metadata []byte `json:"metadata"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) UpdateProvider(ctx context.Context, arg UpdateProviderParams) (Provider, error) {
row := q.db.QueryRow(ctx, updateProvider,
arg.Name,
arg.ClientType,
arg.Icon,
arg.Enable,
arg.Config,
arg.Metadata,
arg.ID,
)
var i Provider
err := row.Scan(
&i.ID,
&i.Name,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const upsertRegistryModel = `-- name: UpsertRegistryModel :one
INSERT INTO models (model_id, name, provider_id, type, config)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (provider_id, model_id) DO UPDATE SET
name = EXCLUDED.name,
type = EXCLUDED.type,
config = EXCLUDED.config,
updated_at = now()
RETURNING id, model_id, name, provider_id, type, config, created_at, updated_at
`
type UpsertRegistryModelParams struct {
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
}
func (q *Queries) UpsertRegistryModel(ctx context.Context, arg UpsertRegistryModelParams) (Model, error) {
row := q.db.QueryRow(ctx, upsertRegistryModel,
arg.ModelID,
arg.Name,
arg.ProviderID,
arg.Type,
arg.Config,
)
var i Model
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const upsertRegistryProvider = `-- name: UpsertRegistryProvider :one
INSERT INTO providers (name, client_type, icon, enable, config, metadata)
VALUES ($1, $2, $3, false, $4, '{}')
ON CONFLICT (name) DO UPDATE SET
icon = EXCLUDED.icon,
client_type = EXCLUDED.client_type,
config = CASE
WHEN providers.config->>'api_key' IS NOT NULL AND providers.config->>'api_key' != ''
THEN jsonb_set(EXCLUDED.config, '{api_key}', providers.config->'api_key')
ELSE EXCLUDED.config
END,
updated_at = now()
RETURNING id, name, client_type, icon, enable, config, metadata, created_at, updated_at
`
type UpsertRegistryProviderParams struct {
Name string `json:"name"`
ClientType string `json:"client_type"`
Icon pgtype.Text `json:"icon"`
Config []byte `json:"config"`
}
func (q *Queries) UpsertRegistryProvider(ctx context.Context, arg UpsertRegistryProviderParams) (Provider, error) {
row := q.db.QueryRow(ctx, upsertRegistryProvider,
arg.Name,
arg.ClientType,
arg.Icon,
arg.Config,
)
var i Provider
err := row.Scan(
&i.ID,
&i.Name,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}