mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-02-04 18:50:57 -06:00
147 lines
3.1 KiB
Go
147 lines
3.1 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.26.0
|
|
// source: publink.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createPublink = `-- name: CreatePublink :exec
|
|
INSERT INTO publinks(name, created_by, root, password_hash, expires, max_accesses) VALUES(
|
|
$1::text,
|
|
$2::text,
|
|
$3::uuid,
|
|
$4::text,
|
|
$5::timestamp,
|
|
$6::int
|
|
)
|
|
`
|
|
|
|
type CreatePublinkParams struct {
|
|
Name string
|
|
CreatedBy string
|
|
Root uuid.UUID
|
|
PasswordHash string
|
|
Expires pgtype.Timestamp
|
|
MaxAccesses int32
|
|
}
|
|
|
|
func (q *Queries) CreatePublink(ctx context.Context, arg CreatePublinkParams) error {
|
|
_, err := q.db.Exec(ctx, createPublink,
|
|
arg.Name,
|
|
arg.CreatedBy,
|
|
arg.Root,
|
|
arg.PasswordHash,
|
|
arg.Expires,
|
|
arg.MaxAccesses,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const getPublink = `-- name: GetPublink :one
|
|
SELECT id, name, created, deleted, created_by, root, accessed, max_accesses, password_hash, expires FROM publinks p WHERE name = $1::text AND deleted IS NULL
|
|
`
|
|
|
|
func (q *Queries) GetPublink(ctx context.Context, name string) (Publink, error) {
|
|
row := q.db.QueryRow(ctx, getPublink, name)
|
|
var i Publink
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Created,
|
|
&i.Deleted,
|
|
&i.CreatedBy,
|
|
&i.Root,
|
|
&i.Accessed,
|
|
&i.MaxAccesses,
|
|
&i.PasswordHash,
|
|
&i.Expires,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const markPublinkAccess = `-- name: MarkPublinkAccess :exec
|
|
UPDATE publinks SET accessed = accessed + 1 WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) MarkPublinkAccess(ctx context.Context, id int32) error {
|
|
_, err := q.db.Exec(ctx, markPublinkAccess, id)
|
|
return err
|
|
}
|
|
|
|
const publinksByCreator = `-- name: PublinksByCreator :many
|
|
SELECT id, name, created, deleted, created_by, root, accessed, max_accesses, password_hash, expires FROM publinks WHERE created_by = $1::text
|
|
`
|
|
|
|
func (q *Queries) PublinksByCreator(ctx context.Context, username string) ([]Publink, error) {
|
|
rows, err := q.db.Query(ctx, publinksByCreator, username)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Publink
|
|
for rows.Next() {
|
|
var i Publink
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Created,
|
|
&i.Deleted,
|
|
&i.CreatedBy,
|
|
&i.Root,
|
|
&i.Accessed,
|
|
&i.MaxAccesses,
|
|
&i.PasswordHash,
|
|
&i.Expires,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const publinksByRoot = `-- name: PublinksByRoot :many
|
|
SELECT id, name, created, deleted, created_by, root, accessed, max_accesses, password_hash, expires FROM publinks WHERE root = $1::uuid
|
|
`
|
|
|
|
func (q *Queries) PublinksByRoot(ctx context.Context, root uuid.UUID) ([]Publink, error) {
|
|
rows, err := q.db.Query(ctx, publinksByRoot, root)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Publink
|
|
for rows.Next() {
|
|
var i Publink
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Created,
|
|
&i.Deleted,
|
|
&i.CreatedBy,
|
|
&i.Root,
|
|
&i.Accessed,
|
|
&i.MaxAccesses,
|
|
&i.PasswordHash,
|
|
&i.Expires,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|