filer/db/queries/queries.sql.go
2023-08-25 02:26:44 +02:00

297 lines
6.1 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.20.0
// source: queries.sql
package queries
import (
"context"
"database/sql"
"github.com/google/uuid"
)
const createFile = `-- name: CreateFile :one
insert into files
(id, user_id, filename, content_type, hash, size, created_at, expires)
values (?1, ?2, ?3, ?4, ?5, ?6, unixepoch(), ?7)
returning id, user_id, filename, content_type, hash, size, created_at, expires
`
type CreateFileParams struct {
ID uuid.UUID
UserID int64
Filename string
ContentType string
Hash string
Size int64
Expires sql.NullInt64
}
func (q *Queries) CreateFile(ctx context.Context, arg CreateFileParams) (File, error) {
row := q.db.QueryRowContext(ctx, createFile,
arg.ID,
arg.UserID,
arg.Filename,
arg.ContentType,
arg.Hash,
arg.Size,
arg.Expires,
)
var i File
err := row.Scan(
&i.ID,
&i.UserID,
&i.Filename,
&i.ContentType,
&i.Hash,
&i.Size,
&i.CreatedAt,
&i.Expires,
)
return i, err
}
const createToken = `-- name: CreateToken :one
insert into tokens (user_id, token) values (?1, ?2)
returning id, user_id, token
`
type CreateTokenParams struct {
UserID int64
Token string
}
func (q *Queries) CreateToken(ctx context.Context, arg CreateTokenParams) (Token, error) {
row := q.db.QueryRowContext(ctx, createToken, arg.UserID, arg.Token)
var i Token
err := row.Scan(&i.ID, &i.UserID, &i.Token)
return i, err
}
const createUser = `-- name: CreateUser :one
insert into users (username, password) values (?1, ?2)
returning id, username, password, is_admin
`
type CreateUserParams struct {
Username string
Password string
}
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
row := q.db.QueryRowContext(ctx, createUser, arg.Username, arg.Password)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Password,
&i.IsAdmin,
)
return i, err
}
const deleteFile = `-- name: DeleteFile :exec
delete from files where id = ?1
`
func (q *Queries) DeleteFile(ctx context.Context, id uuid.UUID) error {
_, err := q.db.ExecContext(ctx, deleteFile, id)
return err
}
const deleteToken = `-- name: DeleteToken :exec
delete from tokens where id = ?1
`
func (q *Queries) DeleteToken(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, deleteToken, id)
return err
}
const deleteUser = `-- name: DeleteUser :exec
delete from users where id = ?1
`
func (q *Queries) DeleteUser(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, deleteUser, id)
return err
}
const getExpiredFiles = `-- name: GetExpiredFiles :many
select id, user_id, filename, content_type, hash, size, created_at, expires from files where expires < unixepoch()
`
func (q *Queries) GetExpiredFiles(ctx context.Context) ([]File, error) {
rows, err := q.db.QueryContext(ctx, getExpiredFiles)
if err != nil {
return nil, err
}
defer rows.Close()
var items []File
for rows.Next() {
var i File
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Filename,
&i.ContentType,
&i.Hash,
&i.Size,
&i.CreatedAt,
&i.Expires,
); 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 getFileByID = `-- name: GetFileByID :one
select id, user_id, filename, content_type, hash, size, created_at, expires from files where id = ?1
`
func (q *Queries) GetFileByID(ctx context.Context, id uuid.UUID) (File, error) {
row := q.db.QueryRowContext(ctx, getFileByID, id)
var i File
err := row.Scan(
&i.ID,
&i.UserID,
&i.Filename,
&i.ContentType,
&i.Hash,
&i.Size,
&i.CreatedAt,
&i.Expires,
)
return i, err
}
const getFileByName = `-- name: GetFileByName :one
select id, user_id, filename, content_type, hash, size, created_at, expires from files where filename = ?1 and hash = ?2
`
type GetFileByNameParams struct {
Filename string
Hash string
}
func (q *Queries) GetFileByName(ctx context.Context, arg GetFileByNameParams) (File, error) {
row := q.db.QueryRowContext(ctx, getFileByName, arg.Filename, arg.Hash)
var i File
err := row.Scan(
&i.ID,
&i.UserID,
&i.Filename,
&i.ContentType,
&i.Hash,
&i.Size,
&i.CreatedAt,
&i.Expires,
)
return i, err
}
const getUser = `-- name: GetUser :one
select id, username, password, is_admin from users where username = ?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.ID,
&i.Username,
&i.Password,
&i.IsAdmin,
)
return i, err
}
const getUserByToken = `-- name: GetUserByToken :one
select u.id, u.username, u.password, u.is_admin from users u join tokens t on u.id = t.user_id
where t.token = ?1
`
func (q *Queries) GetUserByToken(ctx context.Context, token string) (User, error) {
row := q.db.QueryRowContext(ctx, getUserByToken, token)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Password,
&i.IsAdmin,
)
return i, err
}
const getUsers = `-- name: GetUsers :many
select id, username, password, is_admin from users order by id
`
func (q *Queries) GetUsers(ctx context.Context) ([]User, error) {
rows, err := q.db.QueryContext(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.IsAdmin,
); 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 updateUser = `-- name: UpdateUser :one
update users set
username = ?1, password = ?2, is_admin = ?3
where id = ?4
returning id, username, password, is_admin
`
type UpdateUserParams struct {
Username string
Password string
IsAdmin bool
ID int64
}
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error) {
row := q.db.QueryRowContext(ctx, updateUser,
arg.Username,
arg.Password,
arg.IsAdmin,
arg.ID,
)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Password,
&i.IsAdmin,
)
return i, err
}