Files
mantrae/server/internal/store/db/http_middlewares.sql.go
2025-11-12 17:24:59 +01:00

297 lines
6.4 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: http_middlewares.sql
package db
import (
"context"
"github.com/mizuchilabs/mantrae/server/internal/store/schema"
)
const countHttpMiddlewares = `-- name: CountHttpMiddlewares :one
SELECT
COUNT(*)
FROM
http_middlewares
WHERE
profile_id = ?1
AND (
CAST(?2 AS TEXT) IS NULL
OR agent_id = CAST(?2 AS TEXT)
)
`
type CountHttpMiddlewaresParams struct {
ProfileID int64 `json:"profileId"`
AgentID *string `json:"agentId"`
}
func (q *Queries) CountHttpMiddlewares(ctx context.Context, arg CountHttpMiddlewaresParams) (int64, error) {
row := q.queryRow(ctx, q.countHttpMiddlewaresStmt, countHttpMiddlewares, arg.ProfileID, arg.AgentID)
var count int64
err := row.Scan(&count)
return count, err
}
const createHttpMiddleware = `-- name: CreateHttpMiddleware :one
INSERT INTO
http_middlewares (
id,
profile_id,
agent_id,
name,
config,
is_default,
created_at,
updated_at
)
VALUES
(
?,
?,
?,
?,
?,
?,
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
) RETURNING id, profile_id, agent_id, name, config, enabled, is_default, created_at, updated_at
`
type CreateHttpMiddlewareParams struct {
ID string `json:"id"`
ProfileID int64 `json:"profileId"`
AgentID *string `json:"agentId"`
Name string `json:"name"`
Config *schema.HTTPMiddleware `json:"config"`
IsDefault bool `json:"isDefault"`
}
func (q *Queries) CreateHttpMiddleware(ctx context.Context, arg CreateHttpMiddlewareParams) (HttpMiddleware, error) {
row := q.queryRow(ctx, q.createHttpMiddlewareStmt, createHttpMiddleware,
arg.ID,
arg.ProfileID,
arg.AgentID,
arg.Name,
arg.Config,
arg.IsDefault,
)
var i HttpMiddleware
err := row.Scan(
&i.ID,
&i.ProfileID,
&i.AgentID,
&i.Name,
&i.Config,
&i.Enabled,
&i.IsDefault,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteHttpMiddleware = `-- name: DeleteHttpMiddleware :exec
DELETE FROM http_middlewares
WHERE
id = ?
`
func (q *Queries) DeleteHttpMiddleware(ctx context.Context, id string) error {
_, err := q.exec(ctx, q.deleteHttpMiddlewareStmt, deleteHttpMiddleware, id)
return err
}
const getHttpMiddleware = `-- name: GetHttpMiddleware :one
SELECT
id, profile_id, agent_id, name, config, enabled, is_default, created_at, updated_at
FROM
http_middlewares
WHERE
id = ?
`
func (q *Queries) GetHttpMiddleware(ctx context.Context, id string) (HttpMiddleware, error) {
row := q.queryRow(ctx, q.getHttpMiddlewareStmt, getHttpMiddleware, id)
var i HttpMiddleware
err := row.Scan(
&i.ID,
&i.ProfileID,
&i.AgentID,
&i.Name,
&i.Config,
&i.Enabled,
&i.IsDefault,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listHttpMiddlewares = `-- name: ListHttpMiddlewares :many
SELECT
id, profile_id, agent_id, name, config, enabled, is_default, created_at, updated_at
FROM
http_middlewares
WHERE
profile_id = ?1
AND (
CAST(?2 AS TEXT) IS NULL
OR agent_id = CAST(?2 AS TEXT)
)
ORDER BY
created_at DESC
LIMIT
COALESCE(CAST(?4 AS INTEGER), -1)
OFFSET
COALESCE(CAST(?3 AS INTEGER), 0)
`
type ListHttpMiddlewaresParams struct {
ProfileID int64 `json:"profileId"`
AgentID *string `json:"agentId"`
Offset *int64 `json:"offset"`
Limit *int64 `json:"limit"`
}
func (q *Queries) ListHttpMiddlewares(ctx context.Context, arg ListHttpMiddlewaresParams) ([]HttpMiddleware, error) {
rows, err := q.query(ctx, q.listHttpMiddlewaresStmt, listHttpMiddlewares,
arg.ProfileID,
arg.AgentID,
arg.Offset,
arg.Limit,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []HttpMiddleware
for rows.Next() {
var i HttpMiddleware
if err := rows.Scan(
&i.ID,
&i.ProfileID,
&i.AgentID,
&i.Name,
&i.Config,
&i.Enabled,
&i.IsDefault,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listHttpMiddlewaresEnabled = `-- name: ListHttpMiddlewaresEnabled :many
SELECT
id, profile_id, agent_id, name, config, enabled, is_default, created_at, updated_at
FROM
http_middlewares
WHERE
profile_id = ?
AND enabled = TRUE
`
func (q *Queries) ListHttpMiddlewaresEnabled(ctx context.Context, profileID int64) ([]HttpMiddleware, error) {
rows, err := q.query(ctx, q.listHttpMiddlewaresEnabledStmt, listHttpMiddlewaresEnabled, profileID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []HttpMiddleware
for rows.Next() {
var i HttpMiddleware
if err := rows.Scan(
&i.ID,
&i.ProfileID,
&i.AgentID,
&i.Name,
&i.Config,
&i.Enabled,
&i.IsDefault,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const unsetDefaultHttpMiddleware = `-- name: UnsetDefaultHttpMiddleware :exec
UPDATE http_middlewares
SET
is_default = FALSE
WHERE
is_default = TRUE
AND profile_id = ?
`
func (q *Queries) UnsetDefaultHttpMiddleware(ctx context.Context, profileID int64) error {
_, err := q.exec(ctx, q.unsetDefaultHttpMiddlewareStmt, unsetDefaultHttpMiddleware, profileID)
return err
}
const updateHttpMiddleware = `-- name: UpdateHttpMiddleware :one
UPDATE http_middlewares
SET
name = ?,
config = ?,
enabled = ?,
is_default = ?,
updated_at = CURRENT_TIMESTAMP
WHERE
id = ? RETURNING id, profile_id, agent_id, name, config, enabled, is_default, created_at, updated_at
`
type UpdateHttpMiddlewareParams struct {
Name string `json:"name"`
Config *schema.HTTPMiddleware `json:"config"`
Enabled bool `json:"enabled"`
IsDefault bool `json:"isDefault"`
ID string `json:"id"`
}
func (q *Queries) UpdateHttpMiddleware(ctx context.Context, arg UpdateHttpMiddlewareParams) (HttpMiddleware, error) {
row := q.queryRow(ctx, q.updateHttpMiddlewareStmt, updateHttpMiddleware,
arg.Name,
arg.Config,
arg.Enabled,
arg.IsDefault,
arg.ID,
)
var i HttpMiddleware
err := row.Scan(
&i.ID,
&i.ProfileID,
&i.AgentID,
&i.Name,
&i.Config,
&i.Enabled,
&i.IsDefault,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}