2024-07-15 10:12:53 -04:00
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
|
|
// versions:
|
|
|
|
// sqlc v1.26.0
|
2024-07-15 19:03:48 -04:00
|
|
|
// source: users.sql
|
2024-07-15 10:12:53 -04:00
|
|
|
|
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
|
|
)
|
|
|
|
|
2024-07-16 19:31:30 -04:00
|
|
|
const createAPIKey = `-- name: CreateAPIKey :one
|
|
|
|
INSERT INTO api_keys(
|
|
|
|
owner,
|
|
|
|
created_at,
|
|
|
|
expires,
|
|
|
|
disabled,
|
|
|
|
api_key
|
|
|
|
) VALUES ($1, NOW(), $2, $3, gen_random_uuid())
|
|
|
|
RETURNING id, owner, created_at, expires, disabled, api_key
|
|
|
|
`
|
|
|
|
|
|
|
|
type CreateAPIKeyParams struct {
|
|
|
|
Owner pgtype.Int4
|
|
|
|
Expires pgtype.Timestamp
|
|
|
|
Disabled pgtype.Bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CreateAPIKey(ctx context.Context, arg CreateAPIKeyParams) (ApiKey, error) {
|
|
|
|
row := q.db.QueryRow(ctx, createAPIKey, arg.Owner, arg.Expires, arg.Disabled)
|
|
|
|
var i ApiKey
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Owner,
|
|
|
|
&i.CreatedAt,
|
|
|
|
&i.Expires,
|
|
|
|
&i.Disabled,
|
|
|
|
&i.ApiKey,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-07-15 10:12:53 -04:00
|
|
|
const createUser = `-- name: CreateUser :one
|
|
|
|
INSERT INTO users (
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
email,
|
|
|
|
is_admin
|
|
|
|
) VALUES ($1, $2, $3, $4)
|
|
|
|
RETURNING id, username, password, email, is_admin, prefs
|
|
|
|
`
|
|
|
|
|
|
|
|
type CreateUserParams struct {
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
Email string
|
|
|
|
IsAdmin pgtype.Bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
|
|
|
|
row := q.db.QueryRow(ctx, createUser,
|
|
|
|
arg.Username,
|
|
|
|
arg.Password,
|
|
|
|
arg.Email,
|
|
|
|
arg.IsAdmin,
|
|
|
|
)
|
|
|
|
var i User
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Username,
|
|
|
|
&i.Password,
|
|
|
|
&i.Email,
|
|
|
|
&i.IsAdmin,
|
|
|
|
&i.Prefs,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-07-16 19:31:30 -04:00
|
|
|
const deleteAPIKey = `-- name: DeleteAPIKey :exec
|
|
|
|
DELETE FROM api_keys WHERE api_key = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) DeleteAPIKey(ctx context.Context, apiKey pgtype.UUID) error {
|
|
|
|
_, err := q.db.Exec(ctx, deleteAPIKey, apiKey)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-07-15 19:03:48 -04:00
|
|
|
const deleteUser = `-- name: DeleteUser :exec
|
|
|
|
DELETE FROM users WHERE username = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) DeleteUser(ctx context.Context, username string) error {
|
|
|
|
_, err := q.db.Exec(ctx, deleteUser, username)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-07-15 10:12:53 -04:00
|
|
|
const getUserByID = `-- name: GetUserByID :one
|
|
|
|
SELECT id, username, password, email, is_admin, prefs FROM users
|
|
|
|
WHERE id = $1 LIMIT 1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetUserByID(ctx context.Context, id int32) (User, error) {
|
|
|
|
row := q.db.QueryRow(ctx, getUserByID, id)
|
|
|
|
var i User
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Username,
|
|
|
|
&i.Password,
|
|
|
|
&i.Email,
|
|
|
|
&i.IsAdmin,
|
|
|
|
&i.Prefs,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-07-15 19:03:48 -04:00
|
|
|
const getUserByUID = `-- name: GetUserByUID :one
|
|
|
|
SELECT id, username, password, email, is_admin, prefs FROM users
|
|
|
|
WHERE id = $1 LIMIT 1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetUserByUID(ctx context.Context, id int32) (User, error) {
|
|
|
|
row := q.db.QueryRow(ctx, getUserByUID, id)
|
|
|
|
var i User
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Username,
|
|
|
|
&i.Password,
|
|
|
|
&i.Email,
|
|
|
|
&i.IsAdmin,
|
|
|
|
&i.Prefs,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
2024-07-15 10:12:53 -04:00
|
|
|
const getUserByUsername = `-- name: GetUserByUsername :one
|
|
|
|
SELECT id, username, password, email, is_admin, prefs FROM users
|
|
|
|
WHERE username = $1 LIMIT 1
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User, error) {
|
|
|
|
row := q.db.QueryRow(ctx, getUserByUsername, username)
|
|
|
|
var i User
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Username,
|
|
|
|
&i.Password,
|
|
|
|
&i.Email,
|
|
|
|
&i.IsAdmin,
|
|
|
|
&i.Prefs,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const getUsers = `-- name: GetUsers :many
|
|
|
|
SELECT id, username, password, email, is_admin, prefs FROM users
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) GetUsers(ctx context.Context) ([]User, error) {
|
|
|
|
rows, err := q.db.Query(ctx, getUsers)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []User
|
|
|
|
for rows.Next() {
|
|
|
|
var i User
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Username,
|
|
|
|
&i.Password,
|
|
|
|
&i.Email,
|
|
|
|
&i.IsAdmin,
|
|
|
|
&i.Prefs,
|
|
|
|
); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
items = append(items, i)
|
|
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return items, nil
|
|
|
|
}
|
2024-07-15 19:03:48 -04:00
|
|
|
|
|
|
|
const updatePassword = `-- name: UpdatePassword :exec
|
|
|
|
UPDATE users SET password = $2 WHERE username = $1
|
|
|
|
`
|
|
|
|
|
|
|
|
type UpdatePasswordParams struct {
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) UpdatePassword(ctx context.Context, arg UpdatePasswordParams) error {
|
|
|
|
_, err := q.db.Exec(ctx, updatePassword, arg.Username, arg.Password)
|
|
|
|
return err
|
|
|
|
}
|