121 lines
2.2 KiB
Go
121 lines
2.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: idempotency_keys.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createIdempotencyKey = `-- name: CreateIdempotencyKey :execrows
|
|
INSERT INTO idempotency_keys (
|
|
user_id,
|
|
method,
|
|
path,
|
|
key,
|
|
request_hash,
|
|
message_id
|
|
) VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6
|
|
)
|
|
ON CONFLICT DO NOTHING
|
|
`
|
|
|
|
type CreateIdempotencyKeyParams struct {
|
|
UserID uuid.UUID
|
|
Method string
|
|
Path string
|
|
Key string
|
|
RequestHash string
|
|
MessageID uuid.UUID
|
|
}
|
|
|
|
func (q *Queries) CreateIdempotencyKey(ctx context.Context, arg CreateIdempotencyKeyParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, createIdempotencyKey,
|
|
arg.UserID,
|
|
arg.Method,
|
|
arg.Path,
|
|
arg.Key,
|
|
arg.RequestHash,
|
|
arg.MessageID,
|
|
)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const deleteExpiredIdempotencyKeys = `-- name: DeleteExpiredIdempotencyKeys :execrows
|
|
DELETE FROM idempotency_keys
|
|
WHERE created_at < $1
|
|
`
|
|
|
|
func (q *Queries) DeleteExpiredIdempotencyKeys(ctx context.Context, cutoff time.Time) (int64, error) {
|
|
result, err := q.db.Exec(ctx, deleteExpiredIdempotencyKeys, cutoff)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const getIdempotentMessage = `-- name: GetIdempotentMessage :one
|
|
SELECT
|
|
k.request_hash,
|
|
m.id,
|
|
m.chat_id,
|
|
m.sender_id,
|
|
m.text,
|
|
m.created_at
|
|
FROM idempotency_keys AS k
|
|
JOIN messages AS m ON m.id = k.message_id
|
|
WHERE k.user_id = $1
|
|
AND k.method = $2
|
|
AND k.path = $3
|
|
AND k.key = $4
|
|
`
|
|
|
|
type GetIdempotentMessageParams struct {
|
|
UserID uuid.UUID
|
|
Method string
|
|
Path string
|
|
Key string
|
|
}
|
|
|
|
type GetIdempotentMessageRow struct {
|
|
RequestHash string
|
|
ID uuid.UUID
|
|
ChatID uuid.UUID
|
|
SenderID uuid.UUID
|
|
Text string
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
func (q *Queries) GetIdempotentMessage(ctx context.Context, arg GetIdempotentMessageParams) (GetIdempotentMessageRow, error) {
|
|
row := q.db.QueryRow(ctx, getIdempotentMessage,
|
|
arg.UserID,
|
|
arg.Method,
|
|
arg.Path,
|
|
arg.Key,
|
|
)
|
|
var i GetIdempotentMessageRow
|
|
err := row.Scan(
|
|
&i.RequestHash,
|
|
&i.ID,
|
|
&i.ChatID,
|
|
&i.SenderID,
|
|
&i.Text,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|