245 lines
6.5 KiB
Go
245 lines
6.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.28.0
|
|
// source: notification.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CreateNotification = `-- name: CreateNotification :one
|
|
INSERT INTO notifications (
|
|
id, recipient_id, type, level, error_severity, reciever, is_read, delivery_status, delivery_channel, payload, priority, timestamp, metadata
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
|
|
) RETURNING id, recipient_id, type, level, error_severity, reciever, is_read, delivery_status, delivery_channel, payload, priority, version, timestamp, metadata
|
|
`
|
|
|
|
type CreateNotificationParams struct {
|
|
ID string `json:"id"`
|
|
RecipientID int64 `json:"recipient_id"`
|
|
Type string `json:"type"`
|
|
Level string `json:"level"`
|
|
ErrorSeverity pgtype.Text `json:"error_severity"`
|
|
Reciever string `json:"reciever"`
|
|
IsRead bool `json:"is_read"`
|
|
DeliveryStatus string `json:"delivery_status"`
|
|
DeliveryChannel pgtype.Text `json:"delivery_channel"`
|
|
Payload []byte `json:"payload"`
|
|
Priority pgtype.Int4 `json:"priority"`
|
|
Timestamp pgtype.Timestamptz `json:"timestamp"`
|
|
Metadata []byte `json:"metadata"`
|
|
}
|
|
|
|
func (q *Queries) CreateNotification(ctx context.Context, arg CreateNotificationParams) (Notification, error) {
|
|
row := q.db.QueryRow(ctx, CreateNotification,
|
|
arg.ID,
|
|
arg.RecipientID,
|
|
arg.Type,
|
|
arg.Level,
|
|
arg.ErrorSeverity,
|
|
arg.Reciever,
|
|
arg.IsRead,
|
|
arg.DeliveryStatus,
|
|
arg.DeliveryChannel,
|
|
arg.Payload,
|
|
arg.Priority,
|
|
arg.Timestamp,
|
|
arg.Metadata,
|
|
)
|
|
var i Notification
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.RecipientID,
|
|
&i.Type,
|
|
&i.Level,
|
|
&i.ErrorSeverity,
|
|
&i.Reciever,
|
|
&i.IsRead,
|
|
&i.DeliveryStatus,
|
|
&i.DeliveryChannel,
|
|
&i.Payload,
|
|
&i.Priority,
|
|
&i.Version,
|
|
&i.Timestamp,
|
|
&i.Metadata,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetNotification = `-- name: GetNotification :one
|
|
SELECT id, recipient_id, type, level, error_severity, reciever, is_read, delivery_status, delivery_channel, payload, priority, version, timestamp, metadata FROM notifications WHERE id = $1 LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetNotification(ctx context.Context, id string) (Notification, error) {
|
|
row := q.db.QueryRow(ctx, GetNotification, id)
|
|
var i Notification
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.RecipientID,
|
|
&i.Type,
|
|
&i.Level,
|
|
&i.ErrorSeverity,
|
|
&i.Reciever,
|
|
&i.IsRead,
|
|
&i.DeliveryStatus,
|
|
&i.DeliveryChannel,
|
|
&i.Payload,
|
|
&i.Priority,
|
|
&i.Version,
|
|
&i.Timestamp,
|
|
&i.Metadata,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const ListFailedNotifications = `-- name: ListFailedNotifications :many
|
|
SELECT id, recipient_id, type, level, error_severity, reciever, is_read, delivery_status, delivery_channel, payload, priority, version, timestamp, metadata FROM notifications WHERE delivery_status = 'failed' AND timestamp < NOW() - INTERVAL '1 hour' ORDER BY timestamp ASC LIMIT $1
|
|
`
|
|
|
|
func (q *Queries) ListFailedNotifications(ctx context.Context, limit int32) ([]Notification, error) {
|
|
rows, err := q.db.Query(ctx, ListFailedNotifications, limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Notification
|
|
for rows.Next() {
|
|
var i Notification
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.RecipientID,
|
|
&i.Type,
|
|
&i.Level,
|
|
&i.ErrorSeverity,
|
|
&i.Reciever,
|
|
&i.IsRead,
|
|
&i.DeliveryStatus,
|
|
&i.DeliveryChannel,
|
|
&i.Payload,
|
|
&i.Priority,
|
|
&i.Version,
|
|
&i.Timestamp,
|
|
&i.Metadata,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListNotifications = `-- name: ListNotifications :many
|
|
SELECT id, recipient_id, type, level, error_severity, reciever, is_read, delivery_status, delivery_channel, payload, priority, version, timestamp, metadata FROM notifications WHERE recipient_id = $1 ORDER BY timestamp DESC LIMIT $2 OFFSET $3
|
|
`
|
|
|
|
type ListNotificationsParams struct {
|
|
RecipientID int64 `json:"recipient_id"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListNotifications(ctx context.Context, arg ListNotificationsParams) ([]Notification, error) {
|
|
rows, err := q.db.Query(ctx, ListNotifications, arg.RecipientID, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Notification
|
|
for rows.Next() {
|
|
var i Notification
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.RecipientID,
|
|
&i.Type,
|
|
&i.Level,
|
|
&i.ErrorSeverity,
|
|
&i.Reciever,
|
|
&i.IsRead,
|
|
&i.DeliveryStatus,
|
|
&i.DeliveryChannel,
|
|
&i.Payload,
|
|
&i.Priority,
|
|
&i.Version,
|
|
&i.Timestamp,
|
|
&i.Metadata,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListRecipientIDsByReceiver = `-- name: ListRecipientIDsByReceiver :many
|
|
SELECT recipient_id FROM notifications WHERE reciever = $1
|
|
`
|
|
|
|
func (q *Queries) ListRecipientIDsByReceiver(ctx context.Context, reciever string) ([]int64, error) {
|
|
rows, err := q.db.Query(ctx, ListRecipientIDsByReceiver, reciever)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []int64
|
|
for rows.Next() {
|
|
var recipient_id int64
|
|
if err := rows.Scan(&recipient_id); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, recipient_id)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const UpdateNotificationStatus = `-- name: UpdateNotificationStatus :one
|
|
UPDATE notifications SET delivery_status = $2, is_read = $3, metadata = $4 WHERE id = $1 RETURNING id, recipient_id, type, level, error_severity, reciever, is_read, delivery_status, delivery_channel, payload, priority, version, timestamp, metadata
|
|
`
|
|
|
|
type UpdateNotificationStatusParams struct {
|
|
ID string `json:"id"`
|
|
DeliveryStatus string `json:"delivery_status"`
|
|
IsRead bool `json:"is_read"`
|
|
Metadata []byte `json:"metadata"`
|
|
}
|
|
|
|
func (q *Queries) UpdateNotificationStatus(ctx context.Context, arg UpdateNotificationStatusParams) (Notification, error) {
|
|
row := q.db.QueryRow(ctx, UpdateNotificationStatus,
|
|
arg.ID,
|
|
arg.DeliveryStatus,
|
|
arg.IsRead,
|
|
arg.Metadata,
|
|
)
|
|
var i Notification
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.RecipientID,
|
|
&i.Type,
|
|
&i.Level,
|
|
&i.ErrorSeverity,
|
|
&i.Reciever,
|
|
&i.IsRead,
|
|
&i.DeliveryStatus,
|
|
&i.DeliveryChannel,
|
|
&i.Payload,
|
|
&i.Priority,
|
|
&i.Version,
|
|
&i.Timestamp,
|
|
&i.Metadata,
|
|
)
|
|
return i, err
|
|
}
|