mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
- Add sqlc.yaml config (SQLite engine, db/queries/sqlite/, db/dbgen/ output) - Pin sqlc v1.30.0 in sqlc.version - Add Makefile with sqlc-install, sqlc-generate, sqlc-verify targets - Write 14 SQL query files covering all DB domains (users, sessions, invites, channels, messages, reactions, voice, roles, attachments, admin, dm, blocks, lockouts, profile) - Commit generated db/dbgen/ package (querier interface + typed fns) - FTS5 search queries remain hand-written in message_queries.go; transactional multi-step operations unchanged in Go
163 lines
4.3 KiB
Go
163 lines
4.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: attachments.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const createAttachment = `-- name: CreateAttachment :exec
|
|
INSERT INTO attachments (id, uploader_id, filename, stored_as, mime_type, size, width, height)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
`
|
|
|
|
type CreateAttachmentParams struct {
|
|
ID string `json:"id"`
|
|
UploaderID *int64 `json:"uploaderId"`
|
|
Filename string `json:"filename"`
|
|
StoredAs string `json:"storedAs"`
|
|
MimeType string `json:"mimeType"`
|
|
Size int64 `json:"size"`
|
|
Width *int64 `json:"width"`
|
|
Height *int64 `json:"height"`
|
|
}
|
|
|
|
func (q *Queries) CreateAttachment(ctx context.Context, arg CreateAttachmentParams) error {
|
|
_, err := q.db.ExecContext(ctx, createAttachment,
|
|
arg.ID,
|
|
arg.UploaderID,
|
|
arg.Filename,
|
|
arg.StoredAs,
|
|
arg.MimeType,
|
|
arg.Size,
|
|
arg.Width,
|
|
arg.Height,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const deleteAttachment = `-- name: DeleteAttachment :exec
|
|
DELETE FROM attachments WHERE id = ?
|
|
`
|
|
|
|
func (q *Queries) DeleteAttachment(ctx context.Context, id string) error {
|
|
_, err := q.db.ExecContext(ctx, deleteAttachment, id)
|
|
return err
|
|
}
|
|
|
|
const deleteOrphanedAttachments = `-- name: DeleteOrphanedAttachments :many
|
|
DELETE FROM attachments WHERE message_id IS NULL AND uploaded_at < ? RETURNING stored_as
|
|
`
|
|
|
|
func (q *Queries) DeleteOrphanedAttachments(ctx context.Context, uploadedAt string) ([]string, error) {
|
|
rows, err := q.db.QueryContext(ctx, deleteOrphanedAttachments, uploadedAt)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []string{}
|
|
for rows.Next() {
|
|
var stored_as string
|
|
if err := rows.Scan(&stored_as); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, stored_as)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getAttachmentByID = `-- name: GetAttachmentByID :one
|
|
SELECT id, message_id, filename, stored_as, mime_type, size, uploaded_at, uploader_id
|
|
FROM attachments WHERE id = ?
|
|
`
|
|
|
|
type GetAttachmentByIDRow struct {
|
|
ID string `json:"id"`
|
|
MessageID *int64 `json:"messageId"`
|
|
Filename string `json:"filename"`
|
|
StoredAs string `json:"storedAs"`
|
|
MimeType string `json:"mimeType"`
|
|
Size int64 `json:"size"`
|
|
UploadedAt string `json:"uploadedAt"`
|
|
UploaderID *int64 `json:"uploaderId"`
|
|
}
|
|
|
|
func (q *Queries) GetAttachmentByID(ctx context.Context, id string) (GetAttachmentByIDRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getAttachmentByID, id)
|
|
var i GetAttachmentByIDRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.MessageID,
|
|
&i.Filename,
|
|
&i.StoredAs,
|
|
&i.MimeType,
|
|
&i.Size,
|
|
&i.UploadedAt,
|
|
&i.UploaderID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getAttachmentWithChannel = `-- name: GetAttachmentWithChannel :one
|
|
SELECT a.id, a.message_id, a.filename, a.stored_as, a.mime_type, a.size,
|
|
a.uploaded_at, a.uploader_id, m.channel_id, c.type
|
|
FROM attachments a
|
|
LEFT JOIN messages m ON m.id = a.message_id
|
|
LEFT JOIN channels c ON c.id = m.channel_id
|
|
WHERE a.id = ?
|
|
`
|
|
|
|
type GetAttachmentWithChannelRow struct {
|
|
ID string `json:"id"`
|
|
MessageID *int64 `json:"messageId"`
|
|
Filename string `json:"filename"`
|
|
StoredAs string `json:"storedAs"`
|
|
MimeType string `json:"mimeType"`
|
|
Size int64 `json:"size"`
|
|
UploadedAt string `json:"uploadedAt"`
|
|
UploaderID *int64 `json:"uploaderId"`
|
|
ChannelID *int64 `json:"channelId"`
|
|
Type *string `json:"type"`
|
|
}
|
|
|
|
func (q *Queries) GetAttachmentWithChannel(ctx context.Context, id string) (GetAttachmentWithChannelRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getAttachmentWithChannel, id)
|
|
var i GetAttachmentWithChannelRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.MessageID,
|
|
&i.Filename,
|
|
&i.StoredAs,
|
|
&i.MimeType,
|
|
&i.Size,
|
|
&i.UploadedAt,
|
|
&i.UploaderID,
|
|
&i.ChannelID,
|
|
&i.Type,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const linkAttachmentToMessage = `-- name: LinkAttachmentToMessage :execresult
|
|
UPDATE attachments SET message_id = ? WHERE id = ? AND message_id IS NULL
|
|
`
|
|
|
|
type LinkAttachmentToMessageParams struct {
|
|
MessageID *int64 `json:"messageId"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) LinkAttachmentToMessage(ctx context.Context, arg LinkAttachmentToMessageParams) (sql.Result, error) {
|
|
return q.db.ExecContext(ctx, linkAttachmentToMessage, arg.MessageID, arg.ID)
|
|
}
|