stillbox/pkg/gordio/database/users.sql.go
2024-07-27 19:25:16 -04:00

207 lines
4.3 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.26.0
// source: users.sql
package database
import (
"context"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
)
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
`
func (q *Queries) CreateAPIKey(ctx context.Context, owner int, expires pgtype.Timestamp, disabled *bool) (ApiKey, error) {
row := q.db.QueryRow(ctx, createAPIKey, owner, expires, disabled)
var i ApiKey
err := row.Scan(
&i.ID,
&i.Owner,
&i.CreatedAt,
&i.Expires,
&i.Disabled,
&i.ApiKey,
)
return i, err
}
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 `json:"username"`
Password string `json:"password"`
Email string `json:"email"`
IsAdmin bool `json:"is_admin"`
}
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
}
const deleteAPIKey = `-- name: DeleteAPIKey :exec
DELETE FROM api_keys WHERE api_key = $1
`
func (q *Queries) DeleteAPIKey(ctx context.Context, apiKey uuid.UUID) error {
_, err := q.db.Exec(ctx, deleteAPIKey, apiKey)
return 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.Exec(ctx, deleteUser, username)
return err
}
const getAPIKey = `-- name: GetAPIKey :one
SELECT id, owner, created_at, expires, disabled, api_key FROM api_keys WHERE api_key = $1
`
func (q *Queries) GetAPIKey(ctx context.Context, apiKey uuid.UUID) (ApiKey, error) {
row := q.db.QueryRow(ctx, getAPIKey, apiKey)
var i ApiKey
err := row.Scan(
&i.ID,
&i.Owner,
&i.CreatedAt,
&i.Expires,
&i.Disabled,
&i.ApiKey,
)
return i, err
}
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
}
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
}
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
}
const updatePassword = `-- name: UpdatePassword :exec
UPDATE users SET password = $2 WHERE username = $1
`
func (q *Queries) UpdatePassword(ctx context.Context, username string, password string) error {
_, err := q.db.Exec(ctx, updatePassword, username, password)
return err
}