mirror of
https://github.com/MizuchiLabs/mantrae.git
synced 2025-12-16 20:05:17 -06:00
286 lines
6.1 KiB
Go
286 lines
6.1 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: http_services.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/mizuchilabs/mantrae/server/internal/store/schema"
|
|
)
|
|
|
|
const countHttpServices = `-- name: CountHttpServices :one
|
|
SELECT
|
|
COUNT(*)
|
|
FROM
|
|
http_services
|
|
WHERE
|
|
profile_id = ?1
|
|
AND (
|
|
CAST(?2 AS TEXT) IS NULL
|
|
OR agent_id = CAST(?2 AS TEXT)
|
|
)
|
|
`
|
|
|
|
type CountHttpServicesParams struct {
|
|
ProfileID int64 `json:"profileId"`
|
|
AgentID *string `json:"agentId"`
|
|
}
|
|
|
|
func (q *Queries) CountHttpServices(ctx context.Context, arg *CountHttpServicesParams) (int64, error) {
|
|
row := q.queryRow(ctx, q.countHttpServicesStmt, countHttpServices, arg.ProfileID, arg.AgentID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createHttpService = `-- name: CreateHttpService :one
|
|
INSERT INTO
|
|
http_services (id, profile_id, agent_id, name, config)
|
|
VALUES
|
|
(?, ?, ?, ?, ?) RETURNING id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
`
|
|
|
|
type CreateHttpServiceParams struct {
|
|
ID string `json:"id"`
|
|
ProfileID int64 `json:"profileId"`
|
|
AgentID *string `json:"agentId"`
|
|
Name string `json:"name"`
|
|
Config *schema.HTTPService `json:"config"`
|
|
}
|
|
|
|
func (q *Queries) CreateHttpService(ctx context.Context, arg *CreateHttpServiceParams) (*HttpService, error) {
|
|
row := q.queryRow(ctx, q.createHttpServiceStmt, createHttpService,
|
|
arg.ID,
|
|
arg.ProfileID,
|
|
arg.AgentID,
|
|
arg.Name,
|
|
arg.Config,
|
|
)
|
|
var i HttpService
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.AgentID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const deleteHttpService = `-- name: DeleteHttpService :exec
|
|
DELETE FROM http_services
|
|
WHERE
|
|
id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteHttpService(ctx context.Context, id string) error {
|
|
_, err := q.exec(ctx, q.deleteHttpServiceStmt, deleteHttpService, id)
|
|
return err
|
|
}
|
|
|
|
const getHttpService = `-- name: GetHttpService :one
|
|
SELECT
|
|
id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
FROM
|
|
http_services
|
|
WHERE
|
|
id = ?
|
|
`
|
|
|
|
func (q *Queries) GetHttpService(ctx context.Context, id string) (*HttpService, error) {
|
|
row := q.queryRow(ctx, q.getHttpServiceStmt, getHttpService, id)
|
|
var i HttpService
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.AgentID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getHttpServiceByName = `-- name: GetHttpServiceByName :one
|
|
SELECT
|
|
id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
FROM
|
|
http_services
|
|
WHERE
|
|
profile_id = ?
|
|
AND name = ?
|
|
`
|
|
|
|
type GetHttpServiceByNameParams struct {
|
|
ProfileID int64 `json:"profileId"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
func (q *Queries) GetHttpServiceByName(ctx context.Context, arg *GetHttpServiceByNameParams) (*HttpService, error) {
|
|
row := q.queryRow(ctx, q.getHttpServiceByNameStmt, getHttpServiceByName, arg.ProfileID, arg.Name)
|
|
var i HttpService
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.AgentID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const listHttpServices = `-- name: ListHttpServices :many
|
|
SELECT
|
|
id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
FROM
|
|
http_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 ListHttpServicesParams struct {
|
|
ProfileID int64 `json:"profileId"`
|
|
AgentID *string `json:"agentId"`
|
|
Offset *int64 `json:"offset"`
|
|
Limit *int64 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) ListHttpServices(ctx context.Context, arg *ListHttpServicesParams) ([]*HttpService, error) {
|
|
rows, err := q.query(ctx, q.listHttpServicesStmt, listHttpServices,
|
|
arg.ProfileID,
|
|
arg.AgentID,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []*HttpService
|
|
for rows.Next() {
|
|
var i HttpService
|
|
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 listHttpServicesEnabled = `-- name: ListHttpServicesEnabled :many
|
|
SELECT
|
|
id, profile_id, agent_id, name, config, enabled, created_at, updated_at
|
|
FROM
|
|
http_services
|
|
WHERE
|
|
profile_id = ?
|
|
AND enabled = TRUE
|
|
`
|
|
|
|
func (q *Queries) ListHttpServicesEnabled(ctx context.Context, profileID int64) ([]*HttpService, error) {
|
|
rows, err := q.query(ctx, q.listHttpServicesEnabledStmt, listHttpServicesEnabled, profileID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []*HttpService
|
|
for rows.Next() {
|
|
var i HttpService
|
|
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 updateHttpService = `-- name: UpdateHttpService :one
|
|
UPDATE http_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 UpdateHttpServiceParams struct {
|
|
Name string `json:"name"`
|
|
Config *schema.HTTPService `json:"config"`
|
|
Enabled bool `json:"enabled"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateHttpService(ctx context.Context, arg *UpdateHttpServiceParams) (*HttpService, error) {
|
|
row := q.queryRow(ctx, q.updateHttpServiceStmt, updateHttpService,
|
|
arg.Name,
|
|
arg.Config,
|
|
arg.Enabled,
|
|
arg.ID,
|
|
)
|
|
var i HttpService
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.AgentID,
|
|
&i.Name,
|
|
&i.Config,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return &i, err
|
|
}
|