-
Notifications
You must be signed in to change notification settings - Fork 123
/
api_tokens.sql.go
81 lines (73 loc) · 1.59 KB
/
api_tokens.sql.go
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
80
81
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.24.0
// source: api_tokens.sql
package dbsqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const createAPIToken = `-- name: CreateAPIToken :one
INSERT INTO "APIToken" (
"id",
"createdAt",
"updatedAt",
"tenantId",
"name",
"expiresAt"
) VALUES (
coalesce($1::uuid, gen_random_uuid()),
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
$2::uuid,
$3::text,
$4::timestamp
) RETURNING id, "createdAt", "updatedAt", "expiresAt", revoked, name, "tenantId"
`
type CreateAPITokenParams struct {
ID pgtype.UUID `json:"id"`
TenantId pgtype.UUID `json:"tenantId"`
Name pgtype.Text `json:"name"`
Expiresat pgtype.Timestamp `json:"expiresat"`
}
func (q *Queries) CreateAPIToken(ctx context.Context, db DBTX, arg CreateAPITokenParams) (*APIToken, error) {
row := db.QueryRow(ctx, createAPIToken,
arg.ID,
arg.TenantId,
arg.Name,
arg.Expiresat,
)
var i APIToken
err := row.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.ExpiresAt,
&i.Revoked,
&i.Name,
&i.TenantId,
)
return &i, err
}
const getAPITokenById = `-- name: GetAPITokenById :one
SELECT
id, "createdAt", "updatedAt", "expiresAt", revoked, name, "tenantId"
FROM
"APIToken"
WHERE
"id" = $1::uuid
`
func (q *Queries) GetAPITokenById(ctx context.Context, db DBTX, id pgtype.UUID) (*APIToken, error) {
row := db.QueryRow(ctx, getAPITokenById, id)
var i APIToken
err := row.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.ExpiresAt,
&i.Revoked,
&i.Name,
&i.TenantId,
)
return &i, err
}