166 lines
3.9 KiB
Go
166 lines
3.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: files.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const countFiles = `-- name: CountFiles :one
|
|
SELECT COUNT(*)
|
|
FROM files
|
|
`
|
|
|
|
func (q *Queries) CountFiles(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countFiles)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createFile = `-- name: CreateFile :one
|
|
INSERT INTO files(file_name, file_path, original_name, folder_name, mime_type, file_size, file_url)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
RETURNING id,file_url,file_name,file_size
|
|
`
|
|
|
|
type CreateFileParams struct {
|
|
FileName string `json:"file_name"`
|
|
FilePath string `json:"file_path"`
|
|
OriginalName string `json:"original_name"`
|
|
FolderName string `json:"folder_name"`
|
|
MimeType string `json:"mime_type"`
|
|
FileSize int64 `json:"file_size"`
|
|
FileUrl string `json:"file_url"`
|
|
}
|
|
|
|
type CreateFileRow struct {
|
|
ID int32 `json:"id"`
|
|
FileUrl string `json:"file_url"`
|
|
FileName string `json:"file_name"`
|
|
FileSize int64 `json:"file_size"`
|
|
}
|
|
|
|
func (q *Queries) CreateFile(ctx context.Context, arg CreateFileParams) (CreateFileRow, error) {
|
|
row := q.db.QueryRow(ctx, createFile,
|
|
arg.FileName,
|
|
arg.FilePath,
|
|
arg.OriginalName,
|
|
arg.FolderName,
|
|
arg.MimeType,
|
|
arg.FileSize,
|
|
arg.FileUrl,
|
|
)
|
|
var i CreateFileRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.FileUrl,
|
|
&i.FileName,
|
|
&i.FileSize,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listFiles = `-- name: ListFiles :many
|
|
SELECT f.id, f.file_name, f.file_path, f.file_url, f.original_name, f.folder_name, f.mime_type, f.file_size, f.created_at, f.updated_at,
|
|
CASE
|
|
WHEN m.file_id IS NULL THEN NULL
|
|
ELSE jsonb_build_object(
|
|
'width', m.width,
|
|
'height', m.height,
|
|
'format', m.format
|
|
)
|
|
END AS metadata
|
|
FROM files f
|
|
LEFT JOIN file_image_metadata m
|
|
ON f.id = m.file_id
|
|
ORDER BY f.id DESC
|
|
LIMIT $1 OFFSET $2
|
|
`
|
|
|
|
type ListFilesParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type ListFilesRow struct {
|
|
ID int32 `json:"id"`
|
|
FileName string `json:"file_name"`
|
|
FilePath string `json:"file_path"`
|
|
FileUrl string `json:"file_url"`
|
|
OriginalName string `json:"original_name"`
|
|
FolderName string `json:"folder_name"`
|
|
MimeType string `json:"mime_type"`
|
|
FileSize int64 `json:"file_size"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt *time.Time `json:"updated_at"`
|
|
Metadata interface{} `json:"metadata"`
|
|
}
|
|
|
|
func (q *Queries) ListFiles(ctx context.Context, arg ListFilesParams) ([]ListFilesRow, error) {
|
|
rows, err := q.db.Query(ctx, listFiles, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListFilesRow{}
|
|
for rows.Next() {
|
|
var i ListFilesRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.FileName,
|
|
&i.FilePath,
|
|
&i.FileUrl,
|
|
&i.OriginalName,
|
|
&i.FolderName,
|
|
&i.MimeType,
|
|
&i.FileSize,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Metadata,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listImageFiles = `-- name: ListImageFiles :many
|
|
SELECT id, file_path
|
|
FROM files
|
|
WHERE mime_type LIKE 'image/%'
|
|
`
|
|
|
|
type ListImageFilesRow struct {
|
|
ID int32 `json:"id"`
|
|
FilePath string `json:"file_path"`
|
|
}
|
|
|
|
func (q *Queries) ListImageFiles(ctx context.Context) ([]ListImageFilesRow, error) {
|
|
rows, err := q.db.Query(ctx, listImageFiles)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []ListImageFilesRow{}
|
|
for rows.Next() {
|
|
var i ListImageFilesRow
|
|
if err := rows.Scan(&i.ID, &i.FilePath); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|