2026-09-08 15:36:10 +08:00
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
|
|
|
// versions:
|
|
|
|
|
// sqlc v1.30.0
|
|
|
|
|
// source: query.sql
|
|
|
|
|
|
|
|
|
|
package sqlc
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const getSetting = `-- name: GetSetting :one
|
|
|
|
|
SELECT
|
|
|
|
|
KEY,
|
|
|
|
|
value,
|
|
|
|
|
schema_version,
|
|
|
|
|
updated_by_user_id,
|
|
|
|
|
updated_at
|
|
|
|
|
FROM
|
|
|
|
|
settings
|
|
|
|
|
WHERE
|
|
|
|
|
KEY = $1
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type GetSettingRow struct {
|
|
|
|
|
Key string
|
|
|
|
|
Value []byte
|
|
|
|
|
SchemaVersion int32
|
|
|
|
|
UpdatedByUserID string
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (q *Queries) GetSetting(ctx context.Context, key string) (GetSettingRow, error) {
|
|
|
|
|
row := q.db.QueryRow(ctx, getSetting, key)
|
|
|
|
|
var i GetSettingRow
|
|
|
|
|
err := row.Scan(
|
|
|
|
|
&i.Key,
|
|
|
|
|
&i.Value,
|
|
|
|
|
&i.SchemaVersion,
|
|
|
|
|
&i.UpdatedByUserID,
|
|
|
|
|
&i.UpdatedAt,
|
|
|
|
|
)
|
|
|
|
|
return i, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const listSettings = `-- name: ListSettings :many
|
|
|
|
|
SELECT
|
|
|
|
|
KEY,
|
|
|
|
|
value,
|
|
|
|
|
schema_version,
|
|
|
|
|
updated_by_user_id,
|
|
|
|
|
updated_at
|
|
|
|
|
FROM
|
|
|
|
|
settings
|
|
|
|
|
ORDER BY
|
|
|
|
|
KEY
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type ListSettingsRow struct {
|
|
|
|
|
Key string
|
|
|
|
|
Value []byte
|
|
|
|
|
SchemaVersion int32
|
|
|
|
|
UpdatedByUserID string
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (q *Queries) ListSettings(ctx context.Context) ([]ListSettingsRow, error) {
|
|
|
|
|
rows, err := q.db.Query(ctx, listSettings)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer rows.Close()
|
|
|
|
|
items := []ListSettingsRow{}
|
|
|
|
|
for rows.Next() {
|
|
|
|
|
var i ListSettingsRow
|
|
|
|
|
if err := rows.Scan(
|
|
|
|
|
&i.Key,
|
|
|
|
|
&i.Value,
|
|
|
|
|
&i.SchemaVersion,
|
|
|
|
|
&i.UpdatedByUserID,
|
|
|
|
|
&i.UpdatedAt,
|
|
|
|
|
); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
items = append(items, i)
|
|
|
|
|
}
|
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return items, nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-12 16:27:15 +08:00
|
|
|
const proxyInUse = `-- name: ProxyInUse :one
|
|
|
|
|
SELECT EXISTS (
|
|
|
|
|
SELECT 1 FROM models m WHERE m.proxy_id = $1 AND m.deleted_at IS NULL
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT 1 FROM connectors c WHERE c.proxy_id = $1 AND c.deleted_at IS NULL
|
|
|
|
|
)
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
func (q *Queries) ProxyInUse(ctx context.Context, proxyID string) (bool, error) {
|
|
|
|
|
row := q.db.QueryRow(ctx, proxyInUse, proxyID)
|
|
|
|
|
var exists bool
|
|
|
|
|
err := row.Scan(&exists)
|
|
|
|
|
return exists, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-04 18:48:08 +08:00
|
|
|
const putBranding = `-- name: PutBranding :one
|
|
|
|
|
INSERT INTO settings (key, value, schema_version, updated_by_user_id)
|
|
|
|
|
VALUES ('branding', jsonb_build_object('workspace_name', $1::text, 'product_name', $2::text) ||
|
|
|
|
|
CASE WHEN $3::text = '' THEN '{}'::jsonb ELSE jsonb_build_object('logo_s3_key', $3::text) END,
|
|
|
|
|
1, $4::uuid)
|
|
|
|
|
ON CONFLICT (key) DO UPDATE SET
|
|
|
|
|
value = (settings.value - 'workspace_name' - 'product_name' - 'logo_s3_key' - 'logo_url') || EXCLUDED.value,
|
|
|
|
|
updated_by_user_id = EXCLUDED.updated_by_user_id,
|
|
|
|
|
updated_at = now(),
|
|
|
|
|
revision = settings.revision + 1
|
|
|
|
|
RETURNING key, value, schema_version, updated_by_user_id, updated_at
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type PutBrandingParams struct {
|
|
|
|
|
WorkspaceName string
|
|
|
|
|
ProductName string
|
|
|
|
|
LogoKey string
|
|
|
|
|
UserID string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PutBrandingRow struct {
|
|
|
|
|
Key string
|
|
|
|
|
Value []byte
|
|
|
|
|
SchemaVersion int32
|
|
|
|
|
UpdatedByUserID string
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (q *Queries) PutBranding(ctx context.Context, arg PutBrandingParams) (PutBrandingRow, error) {
|
|
|
|
|
row := q.db.QueryRow(ctx, putBranding,
|
|
|
|
|
arg.WorkspaceName,
|
|
|
|
|
arg.ProductName,
|
|
|
|
|
arg.LogoKey,
|
|
|
|
|
arg.UserID,
|
|
|
|
|
)
|
|
|
|
|
var i PutBrandingRow
|
|
|
|
|
err := row.Scan(
|
|
|
|
|
&i.Key,
|
|
|
|
|
&i.Value,
|
|
|
|
|
&i.SchemaVersion,
|
|
|
|
|
&i.UpdatedByUserID,
|
|
|
|
|
&i.UpdatedAt,
|
|
|
|
|
)
|
|
|
|
|
return i, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const putBrandingLogo = `-- name: PutBrandingLogo :one
|
|
|
|
|
INSERT INTO settings (key, value, schema_version, updated_by_user_id)
|
|
|
|
|
VALUES ('branding', jsonb_build_object('workspace_name', 'Monkey AI', 'product_name', 'MonkeyAI') ||
|
|
|
|
|
CASE WHEN $1::text = '' THEN '{}'::jsonb ELSE jsonb_build_object('logo_s3_key', $1::text) END,
|
|
|
|
|
1, $2::uuid)
|
|
|
|
|
ON CONFLICT (key) DO UPDATE SET
|
|
|
|
|
value = (settings.value - 'logo_s3_key' - 'logo_url') ||
|
|
|
|
|
CASE WHEN $1::text = '' THEN '{}'::jsonb ELSE jsonb_build_object('logo_s3_key', $1::text) END,
|
|
|
|
|
updated_by_user_id = EXCLUDED.updated_by_user_id,
|
|
|
|
|
updated_at = now(),
|
|
|
|
|
revision = settings.revision + 1
|
|
|
|
|
RETURNING key, value, schema_version, updated_by_user_id, updated_at
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type PutBrandingLogoParams struct {
|
|
|
|
|
LogoKey string
|
|
|
|
|
UserID string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PutBrandingLogoRow struct {
|
|
|
|
|
Key string
|
|
|
|
|
Value []byte
|
|
|
|
|
SchemaVersion int32
|
|
|
|
|
UpdatedByUserID string
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (q *Queries) PutBrandingLogo(ctx context.Context, arg PutBrandingLogoParams) (PutBrandingLogoRow, error) {
|
|
|
|
|
row := q.db.QueryRow(ctx, putBrandingLogo, arg.LogoKey, arg.UserID)
|
|
|
|
|
var i PutBrandingLogoRow
|
|
|
|
|
err := row.Scan(
|
|
|
|
|
&i.Key,
|
|
|
|
|
&i.Value,
|
|
|
|
|
&i.SchemaVersion,
|
|
|
|
|
&i.UpdatedByUserID,
|
|
|
|
|
&i.UpdatedAt,
|
|
|
|
|
)
|
|
|
|
|
return i, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-08 15:36:10 +08:00
|
|
|
const putSetting = `-- name: PutSetting :one
|
|
|
|
|
INSERT INTO settings (KEY, value, schema_version, updated_by_user_id)
|
|
|
|
|
VALUES ($1, $2, $3, $4)
|
|
|
|
|
ON CONFLICT (KEY)
|
|
|
|
|
DO UPDATE SET
|
2026-11-04 18:48:08 +08:00
|
|
|
value = CASE WHEN settings.key = 'branding' THEN
|
|
|
|
|
(EXCLUDED.value - 'logo_s3_key' - 'logo_url') ||
|
|
|
|
|
CASE WHEN settings.value ? 'logo_s3_key' THEN jsonb_build_object('logo_s3_key', settings.value -> 'logo_s3_key') ELSE '{}'::jsonb END
|
|
|
|
|
ELSE EXCLUDED.value END,
|
2026-09-08 15:36:10 +08:00
|
|
|
schema_version = EXCLUDED.schema_version,
|
|
|
|
|
updated_by_user_id = EXCLUDED.updated_by_user_id,
|
|
|
|
|
updated_at = now()
|
|
|
|
|
RETURNING KEY,
|
|
|
|
|
value,
|
|
|
|
|
schema_version,
|
|
|
|
|
updated_by_user_id,
|
|
|
|
|
updated_at
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
type PutSettingParams struct {
|
|
|
|
|
Key string
|
|
|
|
|
Value []byte
|
|
|
|
|
SchemaVersion int32
|
|
|
|
|
UpdatedByUserID string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PutSettingRow struct {
|
|
|
|
|
Key string
|
|
|
|
|
Value []byte
|
|
|
|
|
SchemaVersion int32
|
|
|
|
|
UpdatedByUserID string
|
|
|
|
|
UpdatedAt time.Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (q *Queries) PutSetting(ctx context.Context, arg PutSettingParams) (PutSettingRow, error) {
|
|
|
|
|
row := q.db.QueryRow(ctx, putSetting,
|
|
|
|
|
arg.Key,
|
|
|
|
|
arg.Value,
|
|
|
|
|
arg.SchemaVersion,
|
|
|
|
|
arg.UpdatedByUserID,
|
|
|
|
|
)
|
|
|
|
|
var i PutSettingRow
|
|
|
|
|
err := row.Scan(
|
|
|
|
|
&i.Key,
|
|
|
|
|
&i.Value,
|
|
|
|
|
&i.SchemaVersion,
|
|
|
|
|
&i.UpdatedByUserID,
|
|
|
|
|
&i.UpdatedAt,
|
|
|
|
|
)
|
|
|
|
|
return i, err
|
|
|
|
|
}
|