postgres

package
v0.0.1-rc Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentSchemaVersion

func CurrentSchemaVersion() int

CurrentSchemaVersion is the congee_schema_version / app-expected value for this binary.

func PreflightMigrationTarget

func PreflightMigrationTarget(ctx context.Context, dsn string, log zerolog.Logger) storage.MigrationTargetPreflight

PreflightMigrationTarget inspects a Postgres DSN without running DDL or starting LISTEN.

Types

type Notifier

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

Notifier implements storage.EventNotifier using pg_notify and a dedicated pgx LISTEN connection.

func NewNotifier

func NewNotifier(db *bun.DB, dsn, origin string) (*Notifier, error)

NewNotifier starts a background LISTEN loop. Close shuts it down.

func (*Notifier) Close

func (n *Notifier) Close() error

Close stops the listener and waits for the goroutine to exit.

func (*Notifier) Listen

func (n *Notifier) Listen() <-chan string

Listen returns a channel of event IDs originating from other instances.

func (*Notifier) Notify

func (n *Notifier) Notify(eventID string)

Notify publishes new_event after a successful local write (other instances should fan out).

type Store

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

Store is a PostgreSQL-backed storage.Store with LISTEN/NOTIFY fan-out.

func Open

func Open(ctx context.Context, dsn string, instanceID string, log zerolog.Logger) (*Store, error)

Open connects with Bun + pgdriver, runs migrations, and starts the event notifier listener. instanceID is sent as NOTIFY payload origin so this process ignores its own writes. log is used for optional debug traces (use zerolog.Nop() when silent).

func (*Store) AdminStorageSnapshot

func (s *Store) AdminStorageSnapshot(ctx context.Context) (storage.AdminStorageSnapshot, error)

AdminStorageSnapshot implements storage.EventStore snapshot (events and tags only).

func (*Store) Close

func (s *Store) Close() error

Close closes the notifier and database pool.

func (*Store) CountEvents

func (s *Store) CountEvents(ctx context.Context, filters []nostr.Filter) (int, error)

CountEvents returns how many distinct events match any filter (OR) via SQL COUNT.

func (*Store) DeleteEvent

func (s *Store) DeleteEvent(ctx context.Context, id string) error

DeleteEvent removes an event and its tags.

func (*Store) EventIDPrefixExists

func (s *Store) EventIDPrefixExists(ctx context.Context, prefix string, groupID string, requireSameH bool) (bool, error)

EventIDPrefixExists implements storage.Store (NIP-29).

func (*Store) GetLatestGroupAdmins39001

func (s *Store) GetLatestGroupAdmins39001(ctx context.Context, relayPubkey, groupID string) (*nostr.Event, error)

GetLatestGroupAdmins39001 implements storage.Store (NIP-29).

func (*Store) GetLatestGroupMetadata39000

func (s *Store) GetLatestGroupMetadata39000(ctx context.Context, relayPubkey, groupID string) (*nostr.Event, error)

GetLatestGroupMetadata39000 implements storage.Store (NIP-29).

func (*Store) HasEventID

func (s *Store) HasEventID(ctx context.Context, id string) (bool, error)

HasEventID implements storage.Store.

func (*Store) IsGroupMember

func (s *Store) IsGroupMember(ctx context.Context, relayPubkey, groupID, memberPubkey string) (bool, error)

IsGroupMember implements storage.Store (NIP-29).

func (*Store) MigrationRowCounts

func (s *Store) MigrationRowCounts(ctx context.Context) (storage.MigrationCounts, error)

MigrationRowCounts returns table row totals for migration verification.

func (*Store) Notifier

func (s *Store) Notifier() storage.EventNotifier

Notifier returns the store's EventNotifier (same instance receives NOTIFY and exposes Listen).

func (*Store) QueryEventSyncItems

func (s *Store) QueryEventSyncItems(ctx context.Context, filter nostr.Filter) ([]storage.SyncItem, error)

QueryEventSyncItems returns id+created_at rows matching filter, ascending for NIP-77.

func (*Store) QueryEvents

func (s *Store) QueryEvents(ctx context.Context, filters []nostr.Filter) ([]*nostr.Event, error)

QueryEvents returns events matching any of the filters (OR), newest first.

func (*Store) SaveEvent

func (s *Store) SaveEvent(ctx context.Context, ev *nostr.Event) error

SaveEvent persists an event, replacing prior replaceable/addressable rows per NIP-01.

func (*Store) ScanEventsForMigration

func (s *Store) ScanEventsForMigration(ctx context.Context, fn func(*nostr.Event) error) error

ScanEventsForMigration iterates all events in stable order.

func (*Store) SearchEvents

func (s *Store) SearchEvents(ctx context.Context, searchQuery string, constraints nostr.Filter) ([]*nostr.Event, error)

SearchEvents uses tsvector + GIN (NIP-50), ordered by ts_rank_cd descending.

Jump to

Keyboard shortcuts

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