forked from mtusi2026/mtusi2026lab2
Завершить PostgreSQL, Redis-сессии, миграции, таймауты и диагностику. Зафиксировать собственные тесты и доказательства финального прогона: 43 PASS, 0 FAIL, 0 SKIP; 768 HTTP-запросов без ошибок. Добавить официальный отчёт с запуском, архитектурой, SQL-планами и ограничениями. PR отложен до завершения уровня 5.
92 lines
1.7 KiB
Go
92 lines
1.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: messages.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createMessage = `-- name: CreateMessage :one
|
|
INSERT INTO messages (chat_id, sender_id, text)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING id, chat_id, sender_id, text, created_at
|
|
`
|
|
|
|
type CreateMessageParams struct {
|
|
ChatID pgtype.UUID
|
|
SenderID pgtype.UUID
|
|
Text string
|
|
}
|
|
|
|
func (q *Queries) CreateMessage(ctx context.Context, arg CreateMessageParams) (Message, error) {
|
|
row := q.db.QueryRow(ctx, createMessage, arg.ChatID, arg.SenderID, arg.Text)
|
|
var i Message
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ChatID,
|
|
&i.SenderID,
|
|
&i.Text,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getMessagesByChatID = `-- name: GetMessagesByChatID :many
|
|
|
|
SELECT id, chat_id, sender_id, text, created_at
|
|
FROM messages
|
|
WHERE chat_id = $1
|
|
AND (
|
|
$2::timestamptz IS NULL
|
|
OR (created_at, id) >
|
|
($2::timestamptz,
|
|
$3::uuid
|
|
)
|
|
)
|
|
ORDER BY created_at ASC, id ASC
|
|
LIMIT $4
|
|
`
|
|
|
|
type GetMessagesByChatIDParams struct {
|
|
ChatID pgtype.UUID
|
|
AfterCreatedAt pgtype.Timestamptz
|
|
AfterID pgtype.UUID
|
|
LimitCount int32
|
|
}
|
|
|
|
func (q *Queries) GetMessagesByChatID(ctx context.Context, arg GetMessagesByChatIDParams) ([]Message, error) {
|
|
rows, err := q.db.Query(ctx, getMessagesByChatID,
|
|
arg.ChatID,
|
|
arg.AfterCreatedAt,
|
|
arg.AfterID,
|
|
arg.LimitCount,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Message
|
|
for rows.Next() {
|
|
var i Message
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ChatID,
|
|
&i.SenderID,
|
|
&i.Text,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|