Documentation
¶
Overview ¶
Package notification provides PostgreSQL LISTEN/NOTIFY helpers.
Index ¶
- type Consumer
- type Event
- type Handler
- type Notification
- func (b *Notification) Apply(ctx context.Context, ds *pgxext.DataSource) error
- func (b *Notification) BuildSQL() (string, error)
- func (b *Notification) DropSQL() (string, error)
- func (b *Notification) EmptyPayload() *Notification
- func (b *Notification) On(operations ...Operation) *Notification
- func (b *Notification) WithPayloadProperties(props ...PayloadProperty) *Notification
- func (b *Notification) WithRowIDColumn(column string) *Notification
- type Operation
- type Payload
- type PayloadProperty
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.
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 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" )