135 lines
3.3 KiB
Go
135 lines
3.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: storage_locations.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createStorageLocation = `-- name: CreateStorageLocation :one
|
|
INSERT INTO storage_locations (user_id, device_name, role)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING id, user_id, device_name, role, created_at, last_seen_at
|
|
`
|
|
|
|
type CreateStorageLocationParams struct {
|
|
UserID uuid.UUID `json:"user_id"`
|
|
DeviceName string `json:"device_name"`
|
|
Role string `json:"role"`
|
|
}
|
|
|
|
func (q *Queries) CreateStorageLocation(ctx context.Context, arg CreateStorageLocationParams) (StorageLocation, error) {
|
|
row := q.db.QueryRowContext(ctx, createStorageLocation, arg.UserID, arg.DeviceName, arg.Role)
|
|
var i StorageLocation
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.DeviceName,
|
|
&i.Role,
|
|
&i.CreatedAt,
|
|
&i.LastSeenAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteStorageLocation = `-- name: DeleteStorageLocation :exec
|
|
DELETE FROM storage_locations
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteStorageLocation(ctx context.Context, id uuid.UUID) error {
|
|
_, err := q.db.ExecContext(ctx, deleteStorageLocation, id)
|
|
return err
|
|
}
|
|
|
|
const getServerStorageLocation = `-- name: GetServerStorageLocation :one
|
|
SELECT id, user_id, device_name, role, created_at, last_seen_at FROM storage_locations
|
|
WHERE user_id = $1 AND role = 'server'
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetServerStorageLocation(ctx context.Context, userID uuid.UUID) (StorageLocation, error) {
|
|
row := q.db.QueryRowContext(ctx, getServerStorageLocation, userID)
|
|
var i StorageLocation
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.DeviceName,
|
|
&i.Role,
|
|
&i.CreatedAt,
|
|
&i.LastSeenAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getStorageLocation = `-- name: GetStorageLocation :one
|
|
SELECT id, user_id, device_name, role, created_at, last_seen_at FROM storage_locations
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetStorageLocation(ctx context.Context, id uuid.UUID) (StorageLocation, error) {
|
|
row := q.db.QueryRowContext(ctx, getStorageLocation, id)
|
|
var i StorageLocation
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.DeviceName,
|
|
&i.Role,
|
|
&i.CreatedAt,
|
|
&i.LastSeenAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listStorageLocationsByUser = `-- name: ListStorageLocationsByUser :many
|
|
SELECT id, user_id, device_name, role, created_at, last_seen_at FROM storage_locations
|
|
WHERE user_id = $1
|
|
ORDER BY created_at ASC
|
|
`
|
|
|
|
func (q *Queries) ListStorageLocationsByUser(ctx context.Context, userID uuid.UUID) ([]StorageLocation, error) {
|
|
rows, err := q.db.QueryContext(ctx, listStorageLocationsByUser, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []StorageLocation
|
|
for rows.Next() {
|
|
var i StorageLocation
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.DeviceName,
|
|
&i.Role,
|
|
&i.CreatedAt,
|
|
&i.LastSeenAt,
|
|
); 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 updateStorageLocationLastSeen = `-- name: UpdateStorageLocationLastSeen :exec
|
|
UPDATE storage_locations
|
|
SET last_seen_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) UpdateStorageLocationLastSeen(ctx context.Context, id uuid.UUID) error {
|
|
_, err := q.db.ExecContext(ctx, updateStorageLocationLastSeen, id)
|
|
return err
|
|
}
|