195 lines
5.0 KiB
Go
195 lines
5.0 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: resource_placements.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createPlacement = `-- name: CreatePlacement :one
|
|
INSERT INTO resource_placements (resource_id, storage_location_id, status, storage_key, synced_at)
|
|
VALUES ($1, $2, $3, $4, $5)
|
|
RETURNING id, resource_id, storage_location_id, status, storage_key, synced_at, created_at
|
|
`
|
|
|
|
type CreatePlacementParams struct {
|
|
ResourceID uuid.UUID `json:"resource_id"`
|
|
StorageLocationID uuid.UUID `json:"storage_location_id"`
|
|
Status string `json:"status"`
|
|
StorageKey sql.NullString `json:"storage_key"`
|
|
SyncedAt sql.NullTime `json:"synced_at"`
|
|
}
|
|
|
|
func (q *Queries) CreatePlacement(ctx context.Context, arg CreatePlacementParams) (ResourcePlacement, error) {
|
|
row := q.db.QueryRowContext(ctx, createPlacement,
|
|
arg.ResourceID,
|
|
arg.StorageLocationID,
|
|
arg.Status,
|
|
arg.StorageKey,
|
|
arg.SyncedAt,
|
|
)
|
|
var i ResourcePlacement
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ResourceID,
|
|
&i.StorageLocationID,
|
|
&i.Status,
|
|
&i.StorageKey,
|
|
&i.SyncedAt,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deletePlacement = `-- name: DeletePlacement :exec
|
|
DELETE FROM resource_placements
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeletePlacement(ctx context.Context, id uuid.UUID) error {
|
|
_, err := q.db.ExecContext(ctx, deletePlacement, id)
|
|
return err
|
|
}
|
|
|
|
const getPlacement = `-- name: GetPlacement :one
|
|
SELECT id, resource_id, storage_location_id, status, storage_key, synced_at, created_at FROM resource_placements
|
|
WHERE resource_id = $1 AND storage_location_id = $2
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetPlacementParams struct {
|
|
ResourceID uuid.UUID `json:"resource_id"`
|
|
StorageLocationID uuid.UUID `json:"storage_location_id"`
|
|
}
|
|
|
|
func (q *Queries) GetPlacement(ctx context.Context, arg GetPlacementParams) (ResourcePlacement, error) {
|
|
row := q.db.QueryRowContext(ctx, getPlacement, arg.ResourceID, arg.StorageLocationID)
|
|
var i ResourcePlacement
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ResourceID,
|
|
&i.StorageLocationID,
|
|
&i.Status,
|
|
&i.StorageKey,
|
|
&i.SyncedAt,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getServerPlacementByResource = `-- name: GetServerPlacementByResource :one
|
|
SELECT rp.id, rp.resource_id, rp.storage_location_id, rp.status, rp.storage_key, rp.synced_at, rp.created_at FROM resource_placements rp
|
|
JOIN storage_locations sl ON sl.id = rp.storage_location_id
|
|
WHERE rp.resource_id = $1 AND sl.role = 'server'
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetServerPlacementByResource(ctx context.Context, resourceID uuid.UUID) (ResourcePlacement, error) {
|
|
row := q.db.QueryRowContext(ctx, getServerPlacementByResource, resourceID)
|
|
var i ResourcePlacement
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ResourceID,
|
|
&i.StorageLocationID,
|
|
&i.Status,
|
|
&i.StorageKey,
|
|
&i.SyncedAt,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listPlacementsByLocation = `-- name: ListPlacementsByLocation :many
|
|
SELECT id, resource_id, storage_location_id, status, storage_key, synced_at, created_at FROM resource_placements
|
|
WHERE storage_location_id = $1
|
|
`
|
|
|
|
func (q *Queries) ListPlacementsByLocation(ctx context.Context, storageLocationID uuid.UUID) ([]ResourcePlacement, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPlacementsByLocation, storageLocationID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ResourcePlacement
|
|
for rows.Next() {
|
|
var i ResourcePlacement
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ResourceID,
|
|
&i.StorageLocationID,
|
|
&i.Status,
|
|
&i.StorageKey,
|
|
&i.SyncedAt,
|
|
&i.CreatedAt,
|
|
); 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 listPlacementsByResource = `-- name: ListPlacementsByResource :many
|
|
SELECT id, resource_id, storage_location_id, status, storage_key, synced_at, created_at FROM resource_placements
|
|
WHERE resource_id = $1
|
|
`
|
|
|
|
func (q *Queries) ListPlacementsByResource(ctx context.Context, resourceID uuid.UUID) ([]ResourcePlacement, error) {
|
|
rows, err := q.db.QueryContext(ctx, listPlacementsByResource, resourceID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ResourcePlacement
|
|
for rows.Next() {
|
|
var i ResourcePlacement
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ResourceID,
|
|
&i.StorageLocationID,
|
|
&i.Status,
|
|
&i.StorageKey,
|
|
&i.SyncedAt,
|
|
&i.CreatedAt,
|
|
); 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 updatePlacementStatus = `-- name: UpdatePlacementStatus :exec
|
|
UPDATE resource_placements
|
|
SET status = $1, synced_at = CURRENT_TIMESTAMP
|
|
WHERE id = $2
|
|
`
|
|
|
|
type UpdatePlacementStatusParams struct {
|
|
Status string `json:"status"`
|
|
ID uuid.UUID `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdatePlacementStatus(ctx context.Context, arg UpdatePlacementStatusParams) error {
|
|
_, err := q.db.ExecContext(ctx, updatePlacementStatus, arg.Status, arg.ID)
|
|
return err
|
|
}
|