mirror of
https://github.com/MizuchiLabs/mantrae.git
synced 2025-12-16 20:05:17 -06:00
202 lines
4.3 KiB
Go
202 lines
4.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: agents.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
)
|
|
|
|
const countAgents = `-- name: CountAgents :one
|
|
SELECT
|
|
COUNT(*)
|
|
FROM
|
|
agents
|
|
WHERE
|
|
profile_id = ?
|
|
`
|
|
|
|
func (q *Queries) CountAgents(ctx context.Context, profileID int64) (int64, error) {
|
|
row := q.queryRow(ctx, q.countAgentsStmt, countAgents, profileID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createAgent = `-- name: CreateAgent :one
|
|
INSERT INTO
|
|
agents (id, profile_id, token, created_at)
|
|
VALUES
|
|
(?, ?, ?, CURRENT_TIMESTAMP) RETURNING id, profile_id, hostname, public_ip, containers, active_ip, token, created_at, updated_at, private_ip
|
|
`
|
|
|
|
type CreateAgentParams struct {
|
|
ID string `json:"id"`
|
|
ProfileID int64 `json:"profileId"`
|
|
Token string `json:"token"`
|
|
}
|
|
|
|
func (q *Queries) CreateAgent(ctx context.Context, arg CreateAgentParams) (Agent, error) {
|
|
row := q.queryRow(ctx, q.createAgentStmt, createAgent, arg.ID, arg.ProfileID, arg.Token)
|
|
var i Agent
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.Hostname,
|
|
&i.PublicIp,
|
|
&i.Containers,
|
|
&i.ActiveIp,
|
|
&i.Token,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.PrivateIp,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteAgent = `-- name: DeleteAgent :exec
|
|
DELETE FROM agents
|
|
WHERE
|
|
id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteAgent(ctx context.Context, id string) error {
|
|
_, err := q.exec(ctx, q.deleteAgentStmt, deleteAgent, id)
|
|
return err
|
|
}
|
|
|
|
const getAgent = `-- name: GetAgent :one
|
|
SELECT
|
|
id, profile_id, hostname, public_ip, containers, active_ip, token, created_at, updated_at, private_ip
|
|
FROM
|
|
agents
|
|
WHERE
|
|
id = ?
|
|
`
|
|
|
|
func (q *Queries) GetAgent(ctx context.Context, id string) (Agent, error) {
|
|
row := q.queryRow(ctx, q.getAgentStmt, getAgent, id)
|
|
var i Agent
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.Hostname,
|
|
&i.PublicIp,
|
|
&i.Containers,
|
|
&i.ActiveIp,
|
|
&i.Token,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.PrivateIp,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listAgents = `-- name: ListAgents :many
|
|
SELECT
|
|
id, profile_id, hostname, public_ip, containers, active_ip, token, created_at, updated_at, private_ip
|
|
FROM
|
|
agents
|
|
WHERE
|
|
profile_id = ?1
|
|
ORDER BY
|
|
created_at DESC
|
|
LIMIT
|
|
COALESCE(CAST(?3 AS INTEGER), -1)
|
|
OFFSET
|
|
COALESCE(CAST(?2 AS INTEGER), 0)
|
|
`
|
|
|
|
type ListAgentsParams struct {
|
|
ProfileID int64 `json:"profileId"`
|
|
Offset *int64 `json:"offset"`
|
|
Limit *int64 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) ListAgents(ctx context.Context, arg ListAgentsParams) ([]Agent, error) {
|
|
rows, err := q.query(ctx, q.listAgentsStmt, listAgents, arg.ProfileID, arg.Offset, arg.Limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Agent
|
|
for rows.Next() {
|
|
var i Agent
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.Hostname,
|
|
&i.PublicIp,
|
|
&i.Containers,
|
|
&i.ActiveIp,
|
|
&i.Token,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.PrivateIp,
|
|
); 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 updateAgent = `-- name: UpdateAgent :one
|
|
UPDATE agents
|
|
SET
|
|
hostname = COALESCE(?1, hostname),
|
|
public_ip = COALESCE(?2, public_ip),
|
|
private_ip = COALESCE(?3, private_ip),
|
|
active_ip = COALESCE(?4, active_ip),
|
|
containers = COALESCE(?5, containers),
|
|
token = COALESCE(?6, token),
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE
|
|
id = ?7 RETURNING id, profile_id, hostname, public_ip, containers, active_ip, token, created_at, updated_at, private_ip
|
|
`
|
|
|
|
type UpdateAgentParams struct {
|
|
Hostname *string `json:"hostname"`
|
|
PublicIp *string `json:"publicIp"`
|
|
PrivateIp *string `json:"privateIp"`
|
|
ActiveIp *string `json:"activeIp"`
|
|
Containers json.RawMessage `json:"containers"`
|
|
Token *string `json:"token"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateAgent(ctx context.Context, arg UpdateAgentParams) (Agent, error) {
|
|
row := q.queryRow(ctx, q.updateAgentStmt, updateAgent,
|
|
arg.Hostname,
|
|
arg.PublicIp,
|
|
arg.PrivateIp,
|
|
arg.ActiveIp,
|
|
arg.Containers,
|
|
arg.Token,
|
|
arg.ID,
|
|
)
|
|
var i Agent
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProfileID,
|
|
&i.Hostname,
|
|
&i.PublicIp,
|
|
&i.Containers,
|
|
&i.ActiveIp,
|
|
&i.Token,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.PrivateIp,
|
|
)
|
|
return i, err
|
|
}
|