forked from mtusi2026/mtusi2026lab3
21 lines
474 B
SQL
21 lines
474 B
SQL
-- name: CreateMessage :one
|
|
INSERT INTO messages (chat_id, sender_id, text)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING *;
|
|
|
|
-- name: GetMessagesByChatID :many
|
|
|
|
SELECT id, chat_id, sender_id, text, created_at
|
|
FROM messages
|
|
WHERE chat_id = sqlc.arg(chat_id)
|
|
AND (
|
|
sqlc.narg(after_created_at)::timestamptz IS NULL
|
|
OR (created_at, id) >
|
|
(sqlc.narg(after_created_at)::timestamptz,
|
|
sqlc.narg(after_id)::uuid
|
|
)
|
|
)
|
|
ORDER BY created_at ASC, id ASC
|
|
LIMIT sqlc.arg(limit_count);
|
|
|