models.sql.go

  1// Code generated by sqlc. DO NOT EDIT.
  2// versions:
  3//   sqlc v1.30.0
  4// source: models.sql
  5
  6package generated
  7
  8import (
  9	"context"
 10)
 11
 12const createModel = `-- name: CreateModel :one
 13INSERT INTO models (model_id, display_name, provider_type, endpoint, api_key, model_name, max_tokens, tags)
 14VALUES (?, ?, ?, ?, ?, ?, ?, ?)
 15RETURNING model_id, display_name, provider_type, endpoint, api_key, model_name, max_tokens, tags, created_at, updated_at
 16`
 17
 18type CreateModelParams struct {
 19	ModelID      string `json:"model_id"`
 20	DisplayName  string `json:"display_name"`
 21	ProviderType string `json:"provider_type"`
 22	Endpoint     string `json:"endpoint"`
 23	ApiKey       string `json:"api_key"`
 24	ModelName    string `json:"model_name"`
 25	MaxTokens    int64  `json:"max_tokens"`
 26	Tags         string `json:"tags"`
 27}
 28
 29func (q *Queries) CreateModel(ctx context.Context, arg CreateModelParams) (Model, error) {
 30	row := q.db.QueryRowContext(ctx, createModel,
 31		arg.ModelID,
 32		arg.DisplayName,
 33		arg.ProviderType,
 34		arg.Endpoint,
 35		arg.ApiKey,
 36		arg.ModelName,
 37		arg.MaxTokens,
 38		arg.Tags,
 39	)
 40	var i Model
 41	err := row.Scan(
 42		&i.ModelID,
 43		&i.DisplayName,
 44		&i.ProviderType,
 45		&i.Endpoint,
 46		&i.ApiKey,
 47		&i.ModelName,
 48		&i.MaxTokens,
 49		&i.Tags,
 50		&i.CreatedAt,
 51		&i.UpdatedAt,
 52	)
 53	return i, err
 54}
 55
 56const deleteModel = `-- name: DeleteModel :exec
 57DELETE FROM models WHERE model_id = ?
 58`
 59
 60func (q *Queries) DeleteModel(ctx context.Context, modelID string) error {
 61	_, err := q.db.ExecContext(ctx, deleteModel, modelID)
 62	return err
 63}
 64
 65const getModel = `-- name: GetModel :one
 66SELECT model_id, display_name, provider_type, endpoint, api_key, model_name, max_tokens, tags, created_at, updated_at FROM models WHERE model_id = ?
 67`
 68
 69func (q *Queries) GetModel(ctx context.Context, modelID string) (Model, error) {
 70	row := q.db.QueryRowContext(ctx, getModel, modelID)
 71	var i Model
 72	err := row.Scan(
 73		&i.ModelID,
 74		&i.DisplayName,
 75		&i.ProviderType,
 76		&i.Endpoint,
 77		&i.ApiKey,
 78		&i.ModelName,
 79		&i.MaxTokens,
 80		&i.Tags,
 81		&i.CreatedAt,
 82		&i.UpdatedAt,
 83	)
 84	return i, err
 85}
 86
 87const getModels = `-- name: GetModels :many
 88SELECT model_id, display_name, provider_type, endpoint, api_key, model_name, max_tokens, tags, created_at, updated_at FROM models ORDER BY created_at ASC
 89`
 90
 91func (q *Queries) GetModels(ctx context.Context) ([]Model, error) {
 92	rows, err := q.db.QueryContext(ctx, getModels)
 93	if err != nil {
 94		return nil, err
 95	}
 96	defer rows.Close()
 97	items := []Model{}
 98	for rows.Next() {
 99		var i Model
100		if err := rows.Scan(
101			&i.ModelID,
102			&i.DisplayName,
103			&i.ProviderType,
104			&i.Endpoint,
105			&i.ApiKey,
106			&i.ModelName,
107			&i.MaxTokens,
108			&i.Tags,
109			&i.CreatedAt,
110			&i.UpdatedAt,
111		); err != nil {
112			return nil, err
113		}
114		items = append(items, i)
115	}
116	if err := rows.Close(); err != nil {
117		return nil, err
118	}
119	if err := rows.Err(); err != nil {
120		return nil, err
121	}
122	return items, nil
123}
124
125const updateModel = `-- name: UpdateModel :one
126UPDATE models
127SET display_name = ?,
128    provider_type = ?,
129    endpoint = ?,
130    api_key = ?,
131    model_name = ?,
132    max_tokens = ?,
133    tags = ?,
134    updated_at = CURRENT_TIMESTAMP
135WHERE model_id = ?
136RETURNING model_id, display_name, provider_type, endpoint, api_key, model_name, max_tokens, tags, created_at, updated_at
137`
138
139type UpdateModelParams struct {
140	DisplayName  string `json:"display_name"`
141	ProviderType string `json:"provider_type"`
142	Endpoint     string `json:"endpoint"`
143	ApiKey       string `json:"api_key"`
144	ModelName    string `json:"model_name"`
145	MaxTokens    int64  `json:"max_tokens"`
146	Tags         string `json:"tags"`
147	ModelID      string `json:"model_id"`
148}
149
150func (q *Queries) UpdateModel(ctx context.Context, arg UpdateModelParams) (Model, error) {
151	row := q.db.QueryRowContext(ctx, updateModel,
152		arg.DisplayName,
153		arg.ProviderType,
154		arg.Endpoint,
155		arg.ApiKey,
156		arg.ModelName,
157		arg.MaxTokens,
158		arg.Tags,
159		arg.ModelID,
160	)
161	var i Model
162	err := row.Scan(
163		&i.ModelID,
164		&i.DisplayName,
165		&i.ProviderType,
166		&i.Endpoint,
167		&i.ApiKey,
168		&i.ModelName,
169		&i.MaxTokens,
170		&i.Tags,
171		&i.CreatedAt,
172		&i.UpdatedAt,
173	)
174	return i, err
175}