233 lines
5.2 KiB
Go
233 lines
5.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: attachments.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const createAttachment = `-- name: CreateAttachment :execresult
|
|
INSERT INTO attachments (
|
|
principle_id, created, modified, name, filename,
|
|
file, type, size, description, archived
|
|
) VALUES (
|
|
?, NOW(), NOW(), ?, ?, ?, ?, ?, ?, 0
|
|
)
|
|
`
|
|
|
|
type CreateAttachmentParams struct {
|
|
PrincipleID int32 `json:"principle_id"`
|
|
Name string `json:"name"`
|
|
Filename string `json:"filename"`
|
|
File string `json:"file"`
|
|
Type string `json:"type"`
|
|
Size int32 `json:"size"`
|
|
Description string `json:"description"`
|
|
}
|
|
|
|
func (q *Queries) CreateAttachment(ctx context.Context, arg CreateAttachmentParams) (sql.Result, error) {
|
|
return q.db.ExecContext(ctx, createAttachment,
|
|
arg.PrincipleID,
|
|
arg.Name,
|
|
arg.Filename,
|
|
arg.File,
|
|
arg.Type,
|
|
arg.Size,
|
|
arg.Description,
|
|
)
|
|
}
|
|
|
|
const deleteAttachment = `-- name: DeleteAttachment :exec
|
|
UPDATE attachments
|
|
SET archived = 1,
|
|
modified = NOW()
|
|
WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteAttachment(ctx context.Context, id int32) error {
|
|
_, err := q.db.ExecContext(ctx, deleteAttachment, id)
|
|
return err
|
|
}
|
|
|
|
const getAttachment = `-- name: GetAttachment :one
|
|
SELECT id, principle_id, created, modified, name, filename, file, type, size, description, archived FROM attachments
|
|
WHERE id = ? LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetAttachment(ctx context.Context, id int32) (Attachment, error) {
|
|
row := q.db.QueryRowContext(ctx, getAttachment, id)
|
|
var i Attachment
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.PrincipleID,
|
|
&i.Created,
|
|
&i.Modified,
|
|
&i.Name,
|
|
&i.Filename,
|
|
&i.File,
|
|
&i.Type,
|
|
&i.Size,
|
|
&i.Description,
|
|
&i.Archived,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listArchivedAttachments = `-- name: ListArchivedAttachments :many
|
|
SELECT id, principle_id, created, modified, name, filename, file, type, size, description, archived FROM attachments
|
|
WHERE archived = 1
|
|
ORDER BY created DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListArchivedAttachmentsParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListArchivedAttachments(ctx context.Context, arg ListArchivedAttachmentsParams) ([]Attachment, error) {
|
|
rows, err := q.db.QueryContext(ctx, listArchivedAttachments, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Attachment{}
|
|
for rows.Next() {
|
|
var i Attachment
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.PrincipleID,
|
|
&i.Created,
|
|
&i.Modified,
|
|
&i.Name,
|
|
&i.Filename,
|
|
&i.File,
|
|
&i.Type,
|
|
&i.Size,
|
|
&i.Description,
|
|
&i.Archived,
|
|
); 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 listAttachments = `-- name: ListAttachments :many
|
|
SELECT id, principle_id, created, modified, name, filename, file, type, size, description, archived FROM attachments
|
|
WHERE archived = 0
|
|
ORDER BY created DESC
|
|
LIMIT ? OFFSET ?
|
|
`
|
|
|
|
type ListAttachmentsParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListAttachments(ctx context.Context, arg ListAttachmentsParams) ([]Attachment, error) {
|
|
rows, err := q.db.QueryContext(ctx, listAttachments, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Attachment{}
|
|
for rows.Next() {
|
|
var i Attachment
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.PrincipleID,
|
|
&i.Created,
|
|
&i.Modified,
|
|
&i.Name,
|
|
&i.Filename,
|
|
&i.File,
|
|
&i.Type,
|
|
&i.Size,
|
|
&i.Description,
|
|
&i.Archived,
|
|
); 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 listAttachmentsByPrinciple = `-- name: ListAttachmentsByPrinciple :many
|
|
SELECT id, principle_id, created, modified, name, filename, file, type, size, description, archived FROM attachments
|
|
WHERE principle_id = ? AND archived = 0
|
|
ORDER BY created DESC
|
|
`
|
|
|
|
func (q *Queries) ListAttachmentsByPrinciple(ctx context.Context, principleID int32) ([]Attachment, error) {
|
|
rows, err := q.db.QueryContext(ctx, listAttachmentsByPrinciple, principleID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Attachment{}
|
|
for rows.Next() {
|
|
var i Attachment
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.PrincipleID,
|
|
&i.Created,
|
|
&i.Modified,
|
|
&i.Name,
|
|
&i.Filename,
|
|
&i.File,
|
|
&i.Type,
|
|
&i.Size,
|
|
&i.Description,
|
|
&i.Archived,
|
|
); 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 updateAttachment = `-- name: UpdateAttachment :exec
|
|
UPDATE attachments
|
|
SET modified = NOW(),
|
|
name = ?,
|
|
description = ?
|
|
WHERE id = ?
|
|
`
|
|
|
|
type UpdateAttachmentParams struct {
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
ID int32 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateAttachment(ctx context.Context, arg UpdateAttachmentParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateAttachment, arg.Name, arg.Description, arg.ID)
|
|
return err
|
|
}
|