event

package
v0.0.0-...-aea796d Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package event provides real-time change notifications via PG LISTEN/NOTIFY.

Architecture:

DB Trigger (INSERT/UPDATE/DELETE on key tables)
  → PG NOTIFY 'vipas_changes', '{"table":"apps","op":"UPDATE","id":"..."}'
    → Listener (pgdriver LISTEN)
      → Broadcast to all SSE clients

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	Table string `json:"table"` // e.g. "applications", "deployments"
	Op    string `json:"op"`    // INSERT, UPDATE, DELETE
	ID    string `json:"id"`    // row UUID
}

Change represents a single database row change captured by a PG trigger.

type PGSubscriber

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

PGSubscriber listens to PG NOTIFY on the vipas_changes channel and exposes a Go channel of Change events. It automatically reconnects if the database connection is lost.

func NewPGSubscriber

func NewPGSubscriber(db *bun.DB, logger *slog.Logger) (*PGSubscriber, error)

NewPGSubscriber creates a subscriber that auto-reconnects on failure.

func (*PGSubscriber) Changes

func (s *PGSubscriber) Changes() <-chan Change

Changes returns the channel of parsed change events.

func (*PGSubscriber) Close

func (s *PGSubscriber) Close() error

Close stops the subscriber.

type Publisher

type Publisher interface {
	Publish(ctx context.Context, change Change) error
}

Publisher can send a notification (used in tests or manual triggers).

type Subscriber

type Subscriber interface {
	// Changes returns a read-only channel of database change events.
	// The channel is closed when the subscriber is stopped.
	Changes() <-chan Change

	// Close stops listening and releases the connection.
	Close() error
}

Subscriber receives real-time change events from the database.

Jump to

Keyboard shortcuts

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