-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathget_sandbox_record.sql.go
More file actions
79 lines (72 loc) · 1.93 KB
/
get_sandbox_record.sql.go
File metadata and controls
79 lines (72 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: get_sandbox_record.sql
package queries
import (
"context"
"time"
"github.com/google/uuid"
)
const getSandboxRecordByTeamAndSandboxID = `-- name: GetSandboxRecordByTeamAndSandboxID :one
SELECT
sl.sandbox_id,
COALESCE(s.base_env_id, sl.env_id) AS template_id,
sl.vcpu,
sl.ram_mb,
sl.total_disk_size_mb,
sl.started_at,
sl.stopped_at,
c.sandbox_proxy_domain AS domain,
COALESCE(template_alias.alias, '') AS alias
FROM billing.sandbox_logs sl
LEFT JOIN public.teams t ON t.id = sl.team_id
LEFT JOIN public.clusters c ON c.id = t.cluster_id
LEFT JOIN public.snapshots s
ON s.sandbox_id = sl.sandbox_id
AND s.team_id = sl.team_id
LEFT JOIN LATERAL (
SELECT ea.alias
FROM public.env_aliases ea
WHERE ea.env_id = COALESCE(s.base_env_id, sl.env_id)
ORDER BY ea.alias
LIMIT 1
) template_alias ON TRUE
WHERE sl.team_id = $1::uuid
AND sl.sandbox_id = $2::text
AND sl.created_at >= $3::timestamptz
ORDER BY sl.created_at DESC
LIMIT 1
`
type GetSandboxRecordByTeamAndSandboxIDParams struct {
TeamID uuid.UUID
SandboxID string
CreatedAfter time.Time
}
type GetSandboxRecordByTeamAndSandboxIDRow struct {
SandboxID string
TemplateID string
Vcpu int64
RamMb int64
TotalDiskSizeMb int64
StartedAt time.Time
StoppedAt *time.Time
Domain *string
Alias string
}
func (q *Queries) GetSandboxRecordByTeamAndSandboxID(ctx context.Context, arg GetSandboxRecordByTeamAndSandboxIDParams) (GetSandboxRecordByTeamAndSandboxIDRow, error) {
row := q.db.QueryRow(ctx, getSandboxRecordByTeamAndSandboxID, arg.TeamID, arg.SandboxID, arg.CreatedAfter)
var i GetSandboxRecordByTeamAndSandboxIDRow
err := row.Scan(
&i.SandboxID,
&i.TemplateID,
&i.Vcpu,
&i.RamMb,
&i.TotalDiskSizeMb,
&i.StartedAt,
&i.StoppedAt,
&i.Domain,
&i.Alias,
)
return i, err
}