mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-11-23 12:31:32 +08:00
157 lines
3.0 KiB
Go
157 lines
3.0 KiB
Go
// 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
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
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
|
|
value = EXCLUDED.value,
|
|
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
|
|
}
|