notification

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package notification provides PostgreSQL LISTEN/NOTIFY helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer struct {
	// contains filtered or unexported fields
}

Consumer listens on one PostgreSQL channel.

func NewConsumer

func NewConsumer(ds *pgxext.DataSource, channel string) *Consumer

NewConsumer creates a Consumer.

func (*Consumer) Listen

func (c *Consumer) Listen(ctx context.Context, handler Handler) error

Listen receives events until ctx is canceled or handler returns an error.

type Event

type Event struct {
	PID     uint32
	Channel string
	Raw     string
	Payload Payload
}

Event is a received PostgreSQL notification.

type Handler

type Handler func(context.Context, Event) error

Handler handles an Event.

type Notification

type Notification struct {
	// contains filtered or unexported fields
}

Notification builds trigger-based PostgreSQL notifications.

func NewNotification

func NewNotification(table, eventName string) *Notification

NewNotification creates a notification for table and channel.

func (*Notification) Apply

func (b *Notification) Apply(ctx context.Context, ds *pgxext.DataSource) error

Apply installs the notification trigger.

func (*Notification) BuildSQL

func (b *Notification) BuildSQL() (string, error)

BuildSQL builds trigger installation SQL.

func (*Notification) DropSQL

func (b *Notification) DropSQL() (string, error)

DropSQL builds trigger removal SQL.

func (*Notification) EmptyPayload

func (b *Notification) EmptyPayload() *Notification

EmptyPayload emits "{}".

func (*Notification) On

func (b *Notification) On(operations ...Operation) *Notification

On sets the operations that emit notifications.

func (*Notification) WithPayloadProperties

func (b *Notification) WithPayloadProperties(props ...PayloadProperty) *Notification

WithPayloadProperties sets the emitted JSON fields.

func (*Notification) WithRowIDColumn

func (b *Notification) WithRowIDColumn(column string) *Notification

WithRowIDColumn sets the rowId source column.

type Operation

type Operation string

Operation is a PostgreSQL row operation.

const (
	Insert Operation = "INSERT"
	Update Operation = "UPDATE"
	Delete Operation = "DELETE"
)

type Payload

type Payload struct {
	FromState json.RawMessage `json:"fromState,omitempty"`
	ToState   json.RawMessage `json:"toState,omitempty"`
	TableName string          `json:"tableName,omitempty"`
	RowID     any             `json:"rowId,omitempty"`
	CreatedAt string          `json:"createdAt,omitempty"`
}

Payload is a decoded notification payload.

type PayloadProperty

type PayloadProperty string

PayloadProperty is a JSON payload field.

const (
	FromState PayloadProperty = "fromState"
	ToState   PayloadProperty = "toState"
	TableName PayloadProperty = "tableName"
	RowID     PayloadProperty = "rowId"
	CreatedAt PayloadProperty = "createdAt"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL