-
Notifications
You must be signed in to change notification settings - Fork 6
/
users.sql.go
188 lines (169 loc) · 4.34 KB
/
users.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.21.0
// source: users.sql
package db
import (
"context"
"github.com/google/uuid"
)
const createUser = `-- name: CreateUser :one
INSERT INTO users (
uuid,
username,
hashed_credential,
full_name,
email,
permissions
) VALUES (
$1, $2, $3, $4, $5, $6
) RETURNING uuid, username, hashed_credential, full_name, email, permissions, credential_changed_at, created_at
`
type CreateUserParams struct {
Uuid uuid.UUID `json:"uuid"`
Username string `json:"username"`
HashedCredential string `json:"hashed_credential"`
FullName string `json:"full_name"`
Email string `json:"email"`
Permissions string `json:"permissions"`
}
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (*User, error) {
row := q.db.QueryRowContext(ctx, createUser,
arg.Uuid,
arg.Username,
arg.HashedCredential,
arg.FullName,
arg.Email,
arg.Permissions,
)
var i User
err := row.Scan(
&i.Uuid,
&i.Username,
&i.HashedCredential,
&i.FullName,
&i.Email,
&i.Permissions,
&i.CredentialChangedAt,
&i.CreatedAt,
)
return &i, err
}
const deleteUser = `-- name: DeleteUser :exec
DELETE FROM users
WHERE username = $1
`
func (q *Queries) DeleteUser(ctx context.Context, username string) error {
_, err := q.db.ExecContext(ctx, deleteUser, username)
return err
}
const getUser = `-- name: GetUser :one
SELECT uuid, username, hashed_credential, full_name, email, permissions, credential_changed_at, created_at FROM users
WHERE username = $1 LIMIT 1
`
func (q *Queries) GetUser(ctx context.Context, username string) (*User, error) {
row := q.db.QueryRowContext(ctx, getUser, username)
var i User
err := row.Scan(
&i.Uuid,
&i.Username,
&i.HashedCredential,
&i.FullName,
&i.Email,
&i.Permissions,
&i.CredentialChangedAt,
&i.CreatedAt,
)
return &i, err
}
const listUsers = `-- name: ListUsers :many
SELECT uuid, username, hashed_credential, full_name, email, permissions, credential_changed_at, created_at FROM users
ORDER BY username
LIMIT $1
OFFSET $2
`
type ListUsersParams struct {
Limit int32 `json:"limit"`
Offset int32 `json:"offset"`
}
func (q *Queries) ListUsers(ctx context.Context, arg ListUsersParams) ([]*User, error) {
rows, err := q.db.QueryContext(ctx, listUsers, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
items := []*User{}
for rows.Next() {
var i User
if err := rows.Scan(
&i.Uuid,
&i.Username,
&i.HashedCredential,
&i.FullName,
&i.Email,
&i.Permissions,
&i.CredentialChangedAt,
&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 updateUserAuthentication = `-- name: UpdateUserAuthentication :one
UPDATE users
SET hashed_credential = $2, credential_changed_at = now()
WHERE username = $1
RETURNING uuid, username, hashed_credential, full_name, email, permissions, credential_changed_at, created_at
`
type UpdateUserAuthenticationParams struct {
Username string `json:"username"`
HashedCredential string `json:"hashed_credential"`
}
func (q *Queries) UpdateUserAuthentication(ctx context.Context, arg UpdateUserAuthenticationParams) (*User, error) {
row := q.db.QueryRowContext(ctx, updateUserAuthentication, arg.Username, arg.HashedCredential)
var i User
err := row.Scan(
&i.Uuid,
&i.Username,
&i.HashedCredential,
&i.FullName,
&i.Email,
&i.Permissions,
&i.CredentialChangedAt,
&i.CreatedAt,
)
return &i, err
}
const updateUserPermission = `-- name: UpdateUserPermission :one
UPDATE users
SET permissions = $2
WHERE username = $1
RETURNING uuid, username, hashed_credential, full_name, email, permissions, credential_changed_at, created_at
`
type UpdateUserPermissionParams struct {
Username string `json:"username"`
Permissions string `json:"permissions"`
}
func (q *Queries) UpdateUserPermission(ctx context.Context, arg UpdateUserPermissionParams) (*User, error) {
row := q.db.QueryRowContext(ctx, updateUserPermission, arg.Username, arg.Permissions)
var i User
err := row.Scan(
&i.Uuid,
&i.Username,
&i.HashedCredential,
&i.FullName,
&i.Email,
&i.Permissions,
&i.CredentialChangedAt,
&i.CreatedAt,
)
return &i, err
}