mirror of
https://github.com/MizuchiLabs/mantrae.git
synced 2025-12-16 20:05:17 -06:00
384 lines
8.1 KiB
Go
384 lines
8.1 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: tcp_routers.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/mizuchilabs/mantrae/server/internal/store/schema"
|
|
)
|
|
|
|
const countTcpRouters = `-- name: CountTcpRouters :one
|
|
SELECT
|
|
COUNT(*)
|
|
FROM
|
|
tcp_routers
|
|
WHERE
|
|
profile_id = ?1
|
|
AND (
|
|
CAST(?2 AS TEXT) IS NULL
|
|
OR agent_id = CAST(?2 AS TEXT)
|
|
)
|
|
`
|
|
|
|
type CountTcpRoutersParams struct {
|
|
ProfileID int64 `json:"profileId"`
|
|
AgentID *string `json:"agentId"`
|
|
}
|
|
|
|
func (q *Queries) CountTcpRouters(ctx context.Context, arg CountTcpRoutersParams) (int64, error) {
|
|
row := q.queryRow(ctx, q.countTcpRoutersStmt, countTcpRouters, arg.ProfileID, arg.AgentID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createTcpRouter = `-- name: CreateTcpRouter :one
|
|
INSERT INTO
|
|
tcp_routers (
|
|
profile_id,
|
|
agent_id,
|
|
name,
|
|
config,
|
|
created_at,
|
|
updated_at
|
|
)
|
|
VALUES
|
|
(?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) RETURNING id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
`
|
|
|
|
type CreateTcpRouterParams struct {
|
|
ProfileID int64 `json:"profileId"`
|
|
AgentID *string `json:"agentId"`
|
|
Name string `json:"name"`
|
|
Config *schema.TCPRouter `json:"config"`
|
|
}
|
|
|
|
func (q *Queries) CreateTcpRouter(ctx context.Context, arg CreateTcpRouterParams) (TcpRouter, error) {
|
|
row := q.queryRow(ctx, q.createTcpRouterStmt, createTcpRouter,
|
|
arg.ProfileID,
|
|
arg.AgentID,
|
|
arg.Name,
|
|
arg.Config,
|
|
)
|
|
var i TcpRouter
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.AgentID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteTcpRouter = `-- name: DeleteTcpRouter :exec
|
|
DELETE FROM tcp_routers
|
|
WHERE
|
|
id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteTcpRouter(ctx context.Context, id int64) error {
|
|
_, err := q.exec(ctx, q.deleteTcpRouterStmt, deleteTcpRouter, id)
|
|
return err
|
|
}
|
|
|
|
const getTcpRouter = `-- name: GetTcpRouter :one
|
|
SELECT
|
|
id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
FROM
|
|
tcp_routers
|
|
WHERE
|
|
id = ?
|
|
`
|
|
|
|
func (q *Queries) GetTcpRouter(ctx context.Context, id int64) (TcpRouter, error) {
|
|
row := q.queryRow(ctx, q.getTcpRouterStmt, getTcpRouter, id)
|
|
var i TcpRouter
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.AgentID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getTcpRoutersUsingEntryPoint = `-- name: GetTcpRoutersUsingEntryPoint :many
|
|
WITH
|
|
ep_name AS (
|
|
SELECT
|
|
name
|
|
FROM
|
|
entry_points
|
|
WHERE
|
|
entry_points.id = ?
|
|
AND entry_points.profile_id = ?
|
|
)
|
|
SELECT
|
|
r.id,
|
|
r.name,
|
|
r.config,
|
|
r.enabled
|
|
FROM
|
|
tcp_routers r
|
|
JOIN json_each (r.config, '$.entryPoints') je
|
|
JOIN ep_name ep ON je.value = ep.name
|
|
`
|
|
|
|
type GetTcpRoutersUsingEntryPointParams struct {
|
|
ID int64 `json:"id"`
|
|
ProfileID int64 `json:"profileId"`
|
|
}
|
|
|
|
type GetTcpRoutersUsingEntryPointRow struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Config *schema.TCPRouter `json:"config"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
func (q *Queries) GetTcpRoutersUsingEntryPoint(ctx context.Context, arg GetTcpRoutersUsingEntryPointParams) ([]GetTcpRoutersUsingEntryPointRow, error) {
|
|
rows, err := q.query(ctx, q.getTcpRoutersUsingEntryPointStmt, getTcpRoutersUsingEntryPoint, arg.ID, arg.ProfileID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetTcpRoutersUsingEntryPointRow
|
|
for rows.Next() {
|
|
var i GetTcpRoutersUsingEntryPointRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
); 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 getTcpRoutersUsingMiddleware = `-- name: GetTcpRoutersUsingMiddleware :many
|
|
WITH
|
|
mw_name AS (
|
|
SELECT
|
|
name
|
|
FROM
|
|
tcp_middlewares
|
|
WHERE
|
|
tcp_middlewares.id = ?
|
|
AND tcp_middlewares.profile_id = ?
|
|
)
|
|
SELECT
|
|
r.id,
|
|
r.name,
|
|
r.config,
|
|
r.enabled
|
|
FROM
|
|
tcp_routers r
|
|
JOIN json_each (r.config, '$.middlewares') je
|
|
JOIN mw_name mw ON je.value = mw.name
|
|
`
|
|
|
|
type GetTcpRoutersUsingMiddlewareParams struct {
|
|
ID int64 `json:"id"`
|
|
ProfileID int64 `json:"profileId"`
|
|
}
|
|
|
|
type GetTcpRoutersUsingMiddlewareRow struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Config *schema.TCPRouter `json:"config"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
func (q *Queries) GetTcpRoutersUsingMiddleware(ctx context.Context, arg GetTcpRoutersUsingMiddlewareParams) ([]GetTcpRoutersUsingMiddlewareRow, error) {
|
|
rows, err := q.query(ctx, q.getTcpRoutersUsingMiddlewareStmt, getTcpRoutersUsingMiddleware, arg.ID, arg.ProfileID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetTcpRoutersUsingMiddlewareRow
|
|
for rows.Next() {
|
|
var i GetTcpRoutersUsingMiddlewareRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
); 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 listTcpRouters = `-- name: ListTcpRouters :many
|
|
SELECT
|
|
id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
FROM
|
|
tcp_routers
|
|
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 ListTcpRoutersParams struct {
|
|
ProfileID int64 `json:"profileId"`
|
|
AgentID *string `json:"agentId"`
|
|
Offset *int64 `json:"offset"`
|
|
Limit *int64 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) ListTcpRouters(ctx context.Context, arg ListTcpRoutersParams) ([]TcpRouter, error) {
|
|
rows, err := q.query(ctx, q.listTcpRoutersStmt, listTcpRouters,
|
|
arg.ProfileID,
|
|
arg.AgentID,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []TcpRouter
|
|
for rows.Next() {
|
|
var i TcpRouter
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.AgentID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
&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 listTcpRoutersEnabled = `-- name: ListTcpRoutersEnabled :many
|
|
SELECT
|
|
id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
FROM
|
|
tcp_routers
|
|
WHERE
|
|
profile_id = ?
|
|
AND enabled = TRUE
|
|
`
|
|
|
|
func (q *Queries) ListTcpRoutersEnabled(ctx context.Context, profileID int64) ([]TcpRouter, error) {
|
|
rows, err := q.query(ctx, q.listTcpRoutersEnabledStmt, listTcpRoutersEnabled, profileID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []TcpRouter
|
|
for rows.Next() {
|
|
var i TcpRouter
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.AgentID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
&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 updateTcpRouter = `-- name: UpdateTcpRouter :one
|
|
UPDATE tcp_routers
|
|
SET
|
|
name = ?,
|
|
config = ?,
|
|
enabled = ?,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE
|
|
id = ? RETURNING id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
`
|
|
|
|
type UpdateTcpRouterParams struct {
|
|
Name string `json:"name"`
|
|
Config *schema.TCPRouter `json:"config"`
|
|
Enabled bool `json:"enabled"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateTcpRouter(ctx context.Context, arg UpdateTcpRouterParams) (TcpRouter, error) {
|
|
row := q.queryRow(ctx, q.updateTcpRouterStmt, updateTcpRouter,
|
|
arg.Name,
|
|
arg.Config,
|
|
arg.Enabled,
|
|
arg.ID,
|
|
)
|
|
var i TcpRouter
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.AgentID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|