mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-05-12 23:28:34 -05:00
264 lines
5.5 KiB
Go
264 lines
5.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.26.0
|
|
// source: user.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const addBookmark = `-- name: AddBookmark :exec
|
|
UPDATE users
|
|
SET
|
|
bookmarks = CASE WHEN bookmarks ? ($1::uuid)::text THEN bookmarks ELSE bookmarks || to_jsonb(array[$1::uuid]) END,
|
|
modified = NOW()
|
|
WHERE username = $2::text
|
|
`
|
|
|
|
type AddBookmarkParams struct {
|
|
ID uuid.UUID
|
|
Username string
|
|
}
|
|
|
|
func (q *Queries) AddBookmark(ctx context.Context, arg AddBookmarkParams) error {
|
|
_, err := q.db.Exec(ctx, addBookmark, arg.ID, arg.Username)
|
|
return err
|
|
}
|
|
|
|
const allUsers = `-- name: AllUsers :many
|
|
SELECT username, display_name, root, home from users WHERE deleted IS NULL
|
|
`
|
|
|
|
type AllUsersRow struct {
|
|
Username string
|
|
DisplayName string
|
|
Root uuid.UUID
|
|
Home uuid.UUID
|
|
}
|
|
|
|
func (q *Queries) AllUsers(ctx context.Context) ([]AllUsersRow, error) {
|
|
rows, err := q.db.Query(ctx, allUsers)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []AllUsersRow
|
|
for rows.Next() {
|
|
var i AllUsersRow
|
|
if err := rows.Scan(
|
|
&i.Username,
|
|
&i.DisplayName,
|
|
&i.Root,
|
|
&i.Home,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const createUser = `-- name: CreateUser :one
|
|
INSERT INTO users(
|
|
username, display_name, password_hash, root, home
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5
|
|
) RETURNING username, created, modified, display_name, password_hash, deleted, root, home, bookmarks
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
Username string
|
|
DisplayName string
|
|
PasswordHash string
|
|
Root uuid.UUID
|
|
Home uuid.UUID
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
|
|
row := q.db.QueryRow(ctx, createUser,
|
|
arg.Username,
|
|
arg.DisplayName,
|
|
arg.PasswordHash,
|
|
arg.Root,
|
|
arg.Home,
|
|
)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.Username,
|
|
&i.Created,
|
|
&i.Modified,
|
|
&i.DisplayName,
|
|
&i.PasswordHash,
|
|
&i.Deleted,
|
|
&i.Root,
|
|
&i.Home,
|
|
&i.Bookmarks,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listBookmarks = `-- name: ListBookmarks :many
|
|
WITH ids(id) AS(
|
|
SELECT jsonb_array_elements_text(bookmarks)::uuid
|
|
FROM users
|
|
WHERE username = $1::text
|
|
) SELECT r.id, r.permissions, r.name, r.parent, r.dir, r.created, r.modified, r.deleted, r.content_size, r.content_type, r.content_sha256
|
|
FROM ids i
|
|
JOIN resources r
|
|
ON i.id = r.id
|
|
`
|
|
|
|
func (q *Queries) ListBookmarks(ctx context.Context, username string) ([]Resource, error) {
|
|
rows, err := q.db.Query(ctx, listBookmarks, username)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Resource
|
|
for rows.Next() {
|
|
var i Resource
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Permissions,
|
|
&i.Name,
|
|
&i.Parent,
|
|
&i.Dir,
|
|
&i.Created,
|
|
&i.Modified,
|
|
&i.Deleted,
|
|
&i.ContentSize,
|
|
&i.ContentType,
|
|
&i.ContentSha256,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const removeBookmark = `-- name: RemoveBookmark :exec
|
|
UPDATE users
|
|
SET
|
|
bookmarks = bookmarks - ($1::uuid)::text,
|
|
modified = NOW()
|
|
WHERE username = $2::text
|
|
`
|
|
|
|
type RemoveBookmarkParams struct {
|
|
ID uuid.UUID
|
|
Username string
|
|
}
|
|
|
|
func (q *Queries) RemoveBookmark(ctx context.Context, arg RemoveBookmarkParams) error {
|
|
_, err := q.db.Exec(ctx, removeBookmark, arg.ID, arg.Username)
|
|
return err
|
|
}
|
|
|
|
const updateUserDisplayName = `-- name: UpdateUserDisplayName :exec
|
|
UPDATE users
|
|
SET
|
|
display_name = $1,
|
|
modified = NOW()
|
|
WHERE username = $2
|
|
`
|
|
|
|
type UpdateUserDisplayNameParams struct {
|
|
DisplayName string
|
|
Username string
|
|
}
|
|
|
|
func (q *Queries) UpdateUserDisplayName(ctx context.Context, arg UpdateUserDisplayNameParams) error {
|
|
_, err := q.db.Exec(ctx, updateUserDisplayName, arg.DisplayName, arg.Username)
|
|
return err
|
|
}
|
|
|
|
const updateUserHome = `-- name: UpdateUserHome :exec
|
|
UPDATE users
|
|
SET
|
|
home = $1,
|
|
modified = NOW()
|
|
WHERE username = $2
|
|
`
|
|
|
|
type UpdateUserHomeParams struct {
|
|
Home uuid.UUID
|
|
Username string
|
|
}
|
|
|
|
func (q *Queries) UpdateUserHome(ctx context.Context, arg UpdateUserHomeParams) error {
|
|
_, err := q.db.Exec(ctx, updateUserHome, arg.Home, arg.Username)
|
|
return err
|
|
}
|
|
|
|
const updateUserPasswordHash = `-- name: UpdateUserPasswordHash :exec
|
|
UPDATE users
|
|
SET
|
|
password_hash = $1,
|
|
modified = NOW()
|
|
WHERE username = $2
|
|
`
|
|
|
|
type UpdateUserPasswordHashParams struct {
|
|
PasswordHash string
|
|
Username string
|
|
}
|
|
|
|
func (q *Queries) UpdateUserPasswordHash(ctx context.Context, arg UpdateUserPasswordHashParams) error {
|
|
_, err := q.db.Exec(ctx, updateUserPasswordHash, arg.PasswordHash, arg.Username)
|
|
return err
|
|
}
|
|
|
|
const updateUserRoot = `-- name: UpdateUserRoot :exec
|
|
UPDATE users
|
|
SET
|
|
root = $1,
|
|
modified = NOW()
|
|
WHERE username = $2
|
|
`
|
|
|
|
type UpdateUserRootParams struct {
|
|
Root uuid.UUID
|
|
Username string
|
|
}
|
|
|
|
func (q *Queries) UpdateUserRoot(ctx context.Context, arg UpdateUserRootParams) error {
|
|
_, err := q.db.Exec(ctx, updateUserRoot, arg.Root, arg.Username)
|
|
return err
|
|
}
|
|
|
|
const userByUsername = `-- name: UserByUsername :one
|
|
SELECT username, display_name, password_hash, root, home FROM users WHERE username = $1
|
|
`
|
|
|
|
type UserByUsernameRow struct {
|
|
Username string
|
|
DisplayName string
|
|
PasswordHash string
|
|
Root uuid.UUID
|
|
Home uuid.UUID
|
|
}
|
|
|
|
func (q *Queries) UserByUsername(ctx context.Context, username string) (UserByUsernameRow, error) {
|
|
row := q.db.QueryRow(ctx, userByUsername, username)
|
|
var i UserByUsernameRow
|
|
err := row.Scan(
|
|
&i.Username,
|
|
&i.DisplayName,
|
|
&i.PasswordHash,
|
|
&i.Root,
|
|
&i.Home,
|
|
)
|
|
return i, err
|
|
}
|