Files
Memoh/internal/db/sqlc/mcp.sql.go
T
Acbox Liu 64609c2101 feat: MCP OAuth (#178)
* feat: MCP OAuth

* fix: redirect url and oauth
2026-03-04 00:41:05 +08:00

285 lines
6.8 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: mcp.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const createMCPConnection = `-- name: CreateMCPConnection :one
INSERT INTO mcp_connections (bot_id, name, type, config, is_active, auth_type)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, bot_id, name, type, config, is_active, status, tools_cache, last_probed_at, status_message, auth_type, created_at, updated_at
`
type CreateMCPConnectionParams struct {
BotID pgtype.UUID `json:"bot_id"`
Name string `json:"name"`
Type string `json:"type"`
Config []byte `json:"config"`
IsActive bool `json:"is_active"`
AuthType string `json:"auth_type"`
}
func (q *Queries) CreateMCPConnection(ctx context.Context, arg CreateMCPConnectionParams) (McpConnection, error) {
row := q.db.QueryRow(ctx, createMCPConnection,
arg.BotID,
arg.Name,
arg.Type,
arg.Config,
arg.IsActive,
arg.AuthType,
)
var i McpConnection
err := row.Scan(
&i.ID,
&i.BotID,
&i.Name,
&i.Type,
&i.Config,
&i.IsActive,
&i.Status,
&i.ToolsCache,
&i.LastProbedAt,
&i.StatusMessage,
&i.AuthType,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteMCPConnection = `-- name: DeleteMCPConnection :exec
DELETE FROM mcp_connections
WHERE bot_id = $1 AND id = $2
`
type DeleteMCPConnectionParams struct {
BotID pgtype.UUID `json:"bot_id"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) DeleteMCPConnection(ctx context.Context, arg DeleteMCPConnectionParams) error {
_, err := q.db.Exec(ctx, deleteMCPConnection, arg.BotID, arg.ID)
return err
}
const getMCPConnectionByID = `-- name: GetMCPConnectionByID :one
SELECT id, bot_id, name, type, config, is_active, status, tools_cache, last_probed_at, status_message, auth_type, created_at, updated_at
FROM mcp_connections
WHERE bot_id = $1 AND id = $2
LIMIT 1
`
type GetMCPConnectionByIDParams struct {
BotID pgtype.UUID `json:"bot_id"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) GetMCPConnectionByID(ctx context.Context, arg GetMCPConnectionByIDParams) (McpConnection, error) {
row := q.db.QueryRow(ctx, getMCPConnectionByID, arg.BotID, arg.ID)
var i McpConnection
err := row.Scan(
&i.ID,
&i.BotID,
&i.Name,
&i.Type,
&i.Config,
&i.IsActive,
&i.Status,
&i.ToolsCache,
&i.LastProbedAt,
&i.StatusMessage,
&i.AuthType,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listMCPConnectionsByBotID = `-- name: ListMCPConnectionsByBotID :many
SELECT id, bot_id, name, type, config, is_active, status, tools_cache, last_probed_at, status_message, auth_type, created_at, updated_at
FROM mcp_connections
WHERE bot_id = $1
ORDER BY created_at DESC
`
func (q *Queries) ListMCPConnectionsByBotID(ctx context.Context, botID pgtype.UUID) ([]McpConnection, error) {
rows, err := q.db.Query(ctx, listMCPConnectionsByBotID, botID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []McpConnection
for rows.Next() {
var i McpConnection
if err := rows.Scan(
&i.ID,
&i.BotID,
&i.Name,
&i.Type,
&i.Config,
&i.IsActive,
&i.Status,
&i.ToolsCache,
&i.LastProbedAt,
&i.StatusMessage,
&i.AuthType,
&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 updateMCPConnection = `-- name: UpdateMCPConnection :one
UPDATE mcp_connections
SET name = $3,
type = $4,
config = $5,
is_active = $6,
auth_type = $7,
updated_at = now()
WHERE bot_id = $1 AND id = $2
RETURNING id, bot_id, name, type, config, is_active, status, tools_cache, last_probed_at, status_message, auth_type, created_at, updated_at
`
type UpdateMCPConnectionParams struct {
BotID pgtype.UUID `json:"bot_id"`
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Config []byte `json:"config"`
IsActive bool `json:"is_active"`
AuthType string `json:"auth_type"`
}
func (q *Queries) UpdateMCPConnection(ctx context.Context, arg UpdateMCPConnectionParams) (McpConnection, error) {
row := q.db.QueryRow(ctx, updateMCPConnection,
arg.BotID,
arg.ID,
arg.Name,
arg.Type,
arg.Config,
arg.IsActive,
arg.AuthType,
)
var i McpConnection
err := row.Scan(
&i.ID,
&i.BotID,
&i.Name,
&i.Type,
&i.Config,
&i.IsActive,
&i.Status,
&i.ToolsCache,
&i.LastProbedAt,
&i.StatusMessage,
&i.AuthType,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const updateMCPConnectionAuthType = `-- name: UpdateMCPConnectionAuthType :exec
UPDATE mcp_connections
SET auth_type = $2,
updated_at = now()
WHERE id = $1
`
type UpdateMCPConnectionAuthTypeParams struct {
ID pgtype.UUID `json:"id"`
AuthType string `json:"auth_type"`
}
func (q *Queries) UpdateMCPConnectionAuthType(ctx context.Context, arg UpdateMCPConnectionAuthTypeParams) error {
_, err := q.db.Exec(ctx, updateMCPConnectionAuthType, arg.ID, arg.AuthType)
return err
}
const updateMCPConnectionProbeResult = `-- name: UpdateMCPConnectionProbeResult :exec
UPDATE mcp_connections
SET status = $3,
tools_cache = $4,
last_probed_at = now(),
status_message = $5,
updated_at = now()
WHERE bot_id = $1 AND id = $2
`
type UpdateMCPConnectionProbeResultParams struct {
BotID pgtype.UUID `json:"bot_id"`
ID pgtype.UUID `json:"id"`
Status string `json:"status"`
ToolsCache []byte `json:"tools_cache"`
StatusMessage string `json:"status_message"`
}
func (q *Queries) UpdateMCPConnectionProbeResult(ctx context.Context, arg UpdateMCPConnectionProbeResultParams) error {
_, err := q.db.Exec(ctx, updateMCPConnectionProbeResult,
arg.BotID,
arg.ID,
arg.Status,
arg.ToolsCache,
arg.StatusMessage,
)
return err
}
const upsertMCPConnectionByName = `-- name: UpsertMCPConnectionByName :one
INSERT INTO mcp_connections (bot_id, name, type, config)
VALUES ($1, $2, $3, $4)
ON CONFLICT (bot_id, name)
DO UPDATE SET type = EXCLUDED.type,
config = EXCLUDED.config,
updated_at = now()
RETURNING id, bot_id, name, type, config, is_active, status, tools_cache, last_probed_at, status_message, auth_type, created_at, updated_at
`
type UpsertMCPConnectionByNameParams struct {
BotID pgtype.UUID `json:"bot_id"`
Name string `json:"name"`
Type string `json:"type"`
Config []byte `json:"config"`
}
func (q *Queries) UpsertMCPConnectionByName(ctx context.Context, arg UpsertMCPConnectionByNameParams) (McpConnection, error) {
row := q.db.QueryRow(ctx, upsertMCPConnectionByName,
arg.BotID,
arg.Name,
arg.Type,
arg.Config,
)
var i McpConnection
err := row.Scan(
&i.ID,
&i.BotID,
&i.Name,
&i.Type,
&i.Config,
&i.IsActive,
&i.Status,
&i.ToolsCache,
&i.LastProbedAt,
&i.StatusMessage,
&i.AuthType,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}