// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.30.0 // source: notification.sql package dbgen import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const CountUnreadNotifications = `-- name: CountUnreadNotifications :one SELECT COUNT(*) FROM notifications WHERE user_id = $1 AND is_read = FALSE ` func (q *Queries) CountUnreadNotifications(ctx context.Context, userID int64) (int64, error) { row := q.db.QueryRow(ctx, CountUnreadNotifications, userID) var count int64 err := row.Scan(&count) return count, err } const CreateNotification = `-- name: CreateNotification :one INSERT INTO notifications ( user_id, receiver_type, type, level, channel, title, message, payload ) VALUES ( $1, $2, $3, $4, $5, $6, $7, $8 ) RETURNING id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type ` type CreateNotificationParams struct { UserID int64 `json:"user_id"` ReceiverType string `json:"receiver_type"` Type string `json:"type"` Level string `json:"level"` Channel pgtype.Text `json:"channel"` Title string `json:"title"` Message string `json:"message"` Payload []byte `json:"payload"` } func (q *Queries) CreateNotification(ctx context.Context, arg CreateNotificationParams) (Notification, error) { row := q.db.QueryRow(ctx, CreateNotification, arg.UserID, arg.ReceiverType, arg.Type, arg.Level, arg.Channel, arg.Title, arg.Message, arg.Payload, ) var i Notification err := row.Scan( &i.ID, &i.UserID, &i.Type, &i.Level, &i.Channel, &i.Title, &i.Message, &i.Payload, &i.IsRead, &i.CreatedAt, &i.ReadAt, &i.ReceiverType, ) return i, err } const DeleteUserNotifications = `-- name: DeleteUserNotifications :exec DELETE FROM notifications WHERE user_id = $1 ` func (q *Queries) DeleteUserNotifications(ctx context.Context, userID int64) error { _, err := q.db.Exec(ctx, DeleteUserNotifications, userID) return err } const GetAllNotifications = `-- name: GetAllNotifications :many SELECT id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type FROM notifications ORDER BY created_at DESC LIMIT $1 OFFSET $2 ` type GetAllNotificationsParams struct { Limit int32 `json:"limit"` Offset int32 `json:"offset"` } func (q *Queries) GetAllNotifications(ctx context.Context, arg GetAllNotificationsParams) ([]Notification, error) { rows, err := q.db.Query(ctx, GetAllNotifications, 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.UserID, &i.Type, &i.Level, &i.Channel, &i.Title, &i.Message, &i.Payload, &i.IsRead, &i.CreatedAt, &i.ReadAt, &i.ReceiverType, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const GetFilteredNotificationCount = `-- name: GetFilteredNotificationCount :one SELECT COUNT(*) FROM notifications WHERE ($1::text IS NULL OR channel = $1) AND ($2::text IS NULL OR type = $2) AND ($3::bigint IS NULL OR user_id = $3) AND ($4::boolean IS NULL OR is_read = $4) AND ($5::timestamptz IS NULL OR created_at >= $5) AND ($6::timestamptz IS NULL OR created_at <= $6) ` type GetFilteredNotificationCountParams struct { FilterChannel pgtype.Text `json:"filter_channel"` FilterType pgtype.Text `json:"filter_type"` FilterUserID pgtype.Int8 `json:"filter_user_id"` FilterIsRead pgtype.Bool `json:"filter_is_read"` FilterAfter pgtype.Timestamptz `json:"filter_after"` FilterBefore pgtype.Timestamptz `json:"filter_before"` } func (q *Queries) GetFilteredNotificationCount(ctx context.Context, arg GetFilteredNotificationCountParams) (int64, error) { row := q.db.QueryRow(ctx, GetFilteredNotificationCount, arg.FilterChannel, arg.FilterType, arg.FilterUserID, arg.FilterIsRead, arg.FilterAfter, arg.FilterBefore, ) var count int64 err := row.Scan(&count) return count, err } const GetFilteredNotifications = `-- name: GetFilteredNotifications :many SELECT id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type FROM notifications WHERE ($1::text IS NULL OR channel = $1) AND ($2::text IS NULL OR type = $2) AND ($3::bigint IS NULL OR user_id = $3) AND ($4::boolean IS NULL OR is_read = $4) AND ($5::timestamptz IS NULL OR created_at >= $5) AND ($6::timestamptz IS NULL OR created_at <= $6) ORDER BY created_at DESC LIMIT $8 OFFSET $7 ` type GetFilteredNotificationsParams struct { FilterChannel pgtype.Text `json:"filter_channel"` FilterType pgtype.Text `json:"filter_type"` FilterUserID pgtype.Int8 `json:"filter_user_id"` FilterIsRead pgtype.Bool `json:"filter_is_read"` FilterAfter pgtype.Timestamptz `json:"filter_after"` FilterBefore pgtype.Timestamptz `json:"filter_before"` PageOffset int32 `json:"page_offset"` PageLimit int32 `json:"page_limit"` } func (q *Queries) GetFilteredNotifications(ctx context.Context, arg GetFilteredNotificationsParams) ([]Notification, error) { rows, err := q.db.Query(ctx, GetFilteredNotifications, arg.FilterChannel, arg.FilterType, arg.FilterUserID, arg.FilterIsRead, arg.FilterAfter, arg.FilterBefore, arg.PageOffset, arg.PageLimit, ) 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.UserID, &i.Type, &i.Level, &i.Channel, &i.Title, &i.Message, &i.Payload, &i.IsRead, &i.CreatedAt, &i.ReadAt, &i.ReceiverType, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const GetNotification = `-- name: GetNotification :one SELECT id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type FROM notifications WHERE id = $1 LIMIT 1 ` func (q *Queries) GetNotification(ctx context.Context, id int64) (Notification, error) { row := q.db.QueryRow(ctx, GetNotification, id) var i Notification err := row.Scan( &i.ID, &i.UserID, &i.Type, &i.Level, &i.Channel, &i.Title, &i.Message, &i.Payload, &i.IsRead, &i.CreatedAt, &i.ReadAt, &i.ReceiverType, ) return i, err } const GetTotalNotificationCount = `-- name: GetTotalNotificationCount :one SELECT COUNT(*) FROM notifications ` func (q *Queries) GetTotalNotificationCount(ctx context.Context) (int64, error) { row := q.db.QueryRow(ctx, GetTotalNotificationCount) var count int64 err := row.Scan(&count) return count, err } const GetUserNotificationCount = `-- name: GetUserNotificationCount :one SELECT COUNT(*) FROM notifications WHERE user_id = $1 ` func (q *Queries) GetUserNotificationCount(ctx context.Context, userID int64) (int64, error) { row := q.db.QueryRow(ctx, GetUserNotificationCount, userID) var count int64 err := row.Scan(&count) return count, err } const GetUserNotifications = `-- name: GetUserNotifications :many SELECT id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type FROM notifications WHERE user_id = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3 ` type GetUserNotificationsParams struct { UserID int64 `json:"user_id"` Limit int32 `json:"limit"` Offset int32 `json:"offset"` } func (q *Queries) GetUserNotifications(ctx context.Context, arg GetUserNotificationsParams) ([]Notification, error) { rows, err := q.db.Query(ctx, GetUserNotifications, arg.UserID, 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.UserID, &i.Type, &i.Level, &i.Channel, &i.Title, &i.Message, &i.Payload, &i.IsRead, &i.CreatedAt, &i.ReadAt, &i.ReceiverType, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const MarkAllUserNotificationsAsRead = `-- name: MarkAllUserNotificationsAsRead :exec UPDATE notifications SET is_read = TRUE, read_at = NOW() WHERE user_id = $1 AND is_read = FALSE ` func (q *Queries) MarkAllUserNotificationsAsRead(ctx context.Context, userID int64) error { _, err := q.db.Exec(ctx, MarkAllUserNotificationsAsRead, userID) return err } const MarkAllUserNotificationsAsUnread = `-- name: MarkAllUserNotificationsAsUnread :exec UPDATE notifications SET is_read = FALSE, read_at = NULL WHERE user_id = $1 AND is_read = TRUE ` func (q *Queries) MarkAllUserNotificationsAsUnread(ctx context.Context, userID int64) error { _, err := q.db.Exec(ctx, MarkAllUserNotificationsAsUnread, userID) return err } const MarkNotificationAsRead = `-- name: MarkNotificationAsRead :one UPDATE notifications SET is_read = TRUE, read_at = NOW() WHERE id = $1 RETURNING id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type ` func (q *Queries) MarkNotificationAsRead(ctx context.Context, id int64) (Notification, error) { row := q.db.QueryRow(ctx, MarkNotificationAsRead, id) var i Notification err := row.Scan( &i.ID, &i.UserID, &i.Type, &i.Level, &i.Channel, &i.Title, &i.Message, &i.Payload, &i.IsRead, &i.CreatedAt, &i.ReadAt, &i.ReceiverType, ) return i, err } const MarkNotificationAsUnread = `-- name: MarkNotificationAsUnread :one UPDATE notifications SET is_read = FALSE, read_at = NULL WHERE id = $1 RETURNING id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type ` func (q *Queries) MarkNotificationAsUnread(ctx context.Context, id int64) (Notification, error) { row := q.db.QueryRow(ctx, MarkNotificationAsUnread, id) var i Notification err := row.Scan( &i.ID, &i.UserID, &i.Type, &i.Level, &i.Channel, &i.Title, &i.Message, &i.Payload, &i.IsRead, &i.CreatedAt, &i.ReadAt, &i.ReceiverType, ) return i, err }