database

package
v1.0.0-rc.15 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func GetMigrationVersionWithDB

func GetMigrationVersionWithDB() (uint, bool, error)

GetMigrationVersionWithDB returns the current migration version using an existing GORM database instance

func IsDuplicateKeyError

func IsDuplicateKeyError(err error) bool

func NewGormDB

func NewGormDB(existingPool *pgxpool.Pool) *gorm.DB

NewGormDB creates a GORM instance using an existing *pgxpool.Pool

func NewPgxConnPool

func NewPgxConnPool(cfg PoolConfig) *pgxpool.Pool

func RunMigrations

func RunMigrations(db shared.DB) error

RunMigrations runs all pending database migrations using an existing GORM database instance

Types

type ListeningConnection

type ListeningConnection struct {
	Conn        *pgxpool.Conn
	Subscribers []chan map[string]interface{}
}

type PoolConfig

type PoolConfig struct {
	User     string
	Password string
	Host     string
	Port     string
	DBName   string

	MaxOpenConns    int32
	MinConns        int32
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
}

PoolConfig holds database connection pool configuration This is used by both GORM and pgx pools to ensure consistent connection management

func GetPoolConfigFromEnv

func GetPoolConfigFromEnv() PoolConfig

GetPoolConfigFromEnv reads pool configuration from environment variables Falls back to sensible defaults if not specified

Environment variables: - DB_MAX_OPEN_CONNS: Maximum number of open connections (default: 25) - DB_MAX_IDLE_CONNS: Maximum number of idle connections (default: 5) - DB_CONN_MAX_LIFETIME: Maximum connection lifetime, e.g. "5m" (default: 5 minutes) - DB_CONN_MAX_IDLE_TIME: Maximum idle time before closing, e.g. "1m" (default: 1 minute)

type PostgreSQLBroker

type PostgreSQLBroker struct {
	ID string // Unique identifier for the broker instance
	// contains filtered or unexported fields
}

PostgreSQLBroker implements the Broker interface using PostgreSQL LISTEN/NOTIFY

func NewPostgreSQLBroker

func NewPostgreSQLBroker(db *pgxpool.Pool) (*PostgreSQLBroker, error)

NewPostgreSQLBroker creates a new PostgreSQL broker

func (*PostgreSQLBroker) GetActiveTopics

func (b *PostgreSQLBroker) GetActiveTopics() []shared.PubSubChannel

GetActiveTopics returns a list of topics currently being listened to

func (*PostgreSQLBroker) IsHealthy

func (b *PostgreSQLBroker) IsHealthy() bool

IsHealthy checks if the broker is functioning properly

func (*PostgreSQLBroker) Publish

func (b *PostgreSQLBroker) Publish(ctx context.Context, message shared.PubSubMessage) error

Publish implements the Broker interface

func (*PostgreSQLBroker) SetShouldReceiveOwnMessages

func (b *PostgreSQLBroker) SetShouldReceiveOwnMessages(should bool)

func (*PostgreSQLBroker) Subscribe

func (b *PostgreSQLBroker) Subscribe(topic shared.PubSubChannel) (<-chan map[string]interface{}, error)

Subscribe implements the Broker interface

type PostgreSQLMessage

type PostgreSQLMessage struct {
	ID        string                 `json:"id"`
	Channel   shared.PubSubChannel   `json:"topic"`
	Payload   map[string]interface{} `json:"payload"`
	Timestamp time.Time              `json:"timestamp"`
	SenderID  string                 `json:"sender_id,omitempty"` // Optional field for sender ID
}

func (PostgreSQLMessage) GetChannel

func (m PostgreSQLMessage) GetChannel() shared.PubSubChannel

func (PostgreSQLMessage) GetPayload

func (m PostgreSQLMessage) GetPayload() map[string]interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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