mirror of
https://github.com/MizuchiLabs/mantrae.git
synced 2025-12-16 20:05:17 -06:00
297 lines
6.2 KiB
Go
297 lines
6.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: udp_services.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/mizuchilabs/mantrae/server/internal/store/schema"
|
|
)
|
|
|
|
const countUdpServices = `-- name: CountUdpServices :one
|
|
SELECT
|
|
COUNT(*)
|
|
FROM
|
|
udp_services
|
|
WHERE
|
|
profile_id = ?1
|
|
AND (
|
|
CAST(?2 AS TEXT) IS NULL
|
|
OR agent_id = CAST(?2 AS TEXT)
|
|
)
|
|
`
|
|
|
|
type CountUdpServicesParams struct {
|
|
ProfileID int64 `json:"profileId"`
|
|
AgentID *string `json:"agentId"`
|
|
}
|
|
|
|
func (q *Queries) CountUdpServices(ctx context.Context, arg CountUdpServicesParams) (int64, error) {
|
|
row := q.queryRow(ctx, q.countUdpServicesStmt, countUdpServices, arg.ProfileID, arg.AgentID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createUdpService = `-- name: CreateUdpService :one
|
|
INSERT INTO
|
|
udp_services (
|
|
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 CreateUdpServiceParams struct {
|
|
ProfileID int64 `json:"profileId"`
|
|
AgentID *string `json:"agentId"`
|
|
Name string `json:"name"`
|
|
Config *schema.UDPService `json:"config"`
|
|
}
|
|
|
|
func (q *Queries) CreateUdpService(ctx context.Context, arg CreateUdpServiceParams) (UdpService, error) {
|
|
row := q.queryRow(ctx, q.createUdpServiceStmt, createUdpService,
|
|
arg.ProfileID,
|
|
arg.AgentID,
|
|
arg.Name,
|
|
arg.Config,
|
|
)
|
|
var i UdpService
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.AgentID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteUdpService = `-- name: DeleteUdpService :exec
|
|
DELETE FROM udp_services
|
|
WHERE
|
|
id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteUdpService(ctx context.Context, id int64) error {
|
|
_, err := q.exec(ctx, q.deleteUdpServiceStmt, deleteUdpService, id)
|
|
return err
|
|
}
|
|
|
|
const getUdpServiceByID = `-- name: GetUdpServiceByID :one
|
|
SELECT
|
|
id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
FROM
|
|
udp_services
|
|
WHERE
|
|
profile_id = ?
|
|
AND id = ?
|
|
`
|
|
|
|
type GetUdpServiceByIDParams struct {
|
|
ProfileID int64 `json:"profileId"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) GetUdpServiceByID(ctx context.Context, arg GetUdpServiceByIDParams) (UdpService, error) {
|
|
row := q.queryRow(ctx, q.getUdpServiceByIDStmt, getUdpServiceByID, arg.ProfileID, arg.ID)
|
|
var i UdpService
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.AgentID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getUdpServiceByName = `-- name: GetUdpServiceByName :one
|
|
SELECT
|
|
id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
FROM
|
|
udp_services
|
|
WHERE
|
|
profile_id = ?
|
|
AND name = ?
|
|
`
|
|
|
|
type GetUdpServiceByNameParams struct {
|
|
ProfileID int64 `json:"profileId"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
func (q *Queries) GetUdpServiceByName(ctx context.Context, arg GetUdpServiceByNameParams) (UdpService, error) {
|
|
row := q.queryRow(ctx, q.getUdpServiceByNameStmt, getUdpServiceByName, arg.ProfileID, arg.Name)
|
|
var i UdpService
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.AgentID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listUdpServices = `-- name: ListUdpServices :many
|
|
SELECT
|
|
id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
FROM
|
|
udp_services
|
|
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 ListUdpServicesParams struct {
|
|
ProfileID int64 `json:"profileId"`
|
|
AgentID *string `json:"agentId"`
|
|
Offset *int64 `json:"offset"`
|
|
Limit *int64 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) ListUdpServices(ctx context.Context, arg ListUdpServicesParams) ([]UdpService, error) {
|
|
rows, err := q.query(ctx, q.listUdpServicesStmt, listUdpServices,
|
|
arg.ProfileID,
|
|
arg.AgentID,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []UdpService
|
|
for rows.Next() {
|
|
var i UdpService
|
|
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 listUdpServicesEnabled = `-- name: ListUdpServicesEnabled :many
|
|
SELECT
|
|
id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
FROM
|
|
udp_services
|
|
WHERE
|
|
profile_id = ?
|
|
AND enabled = TRUE
|
|
`
|
|
|
|
func (q *Queries) ListUdpServicesEnabled(ctx context.Context, profileID int64) ([]UdpService, error) {
|
|
rows, err := q.query(ctx, q.listUdpServicesEnabledStmt, listUdpServicesEnabled, profileID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []UdpService
|
|
for rows.Next() {
|
|
var i UdpService
|
|
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 updateUdpService = `-- name: UpdateUdpService :one
|
|
UPDATE udp_services
|
|
SET
|
|
name = ?,
|
|
config = ?,
|
|
enabled = ?,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE
|
|
id = ? RETURNING id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
`
|
|
|
|
type UpdateUdpServiceParams struct {
|
|
Name string `json:"name"`
|
|
Config *schema.UDPService `json:"config"`
|
|
Enabled bool `json:"enabled"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUdpService(ctx context.Context, arg UpdateUdpServiceParams) (UdpService, error) {
|
|
row := q.queryRow(ctx, q.updateUdpServiceStmt, updateUdpService,
|
|
arg.Name,
|
|
arg.Config,
|
|
arg.Enabled,
|
|
arg.ID,
|
|
)
|
|
var i UdpService
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.AgentID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|