Documentation
¶
Index ¶
- Variables
- func GetMigrationVersionWithDB() (uint, bool, error)
- func IsDuplicateKeyError(err error) bool
- func NewGormDB(existingPool *pgxpool.Pool) *gorm.DB
- func NewPgxConnPool(cfg PoolConfig) *pgxpool.Pool
- func RunMigrations(db shared.DB) error
- type ListeningConnection
- type PoolConfig
- type PostgreSQLBroker
- func (b *PostgreSQLBroker) GetActiveTopics() []shared.PubSubChannel
- func (b *PostgreSQLBroker) IsHealthy() bool
- func (b *PostgreSQLBroker) Publish(ctx context.Context, message shared.PubSubMessage) error
- func (b *PostgreSQLBroker) SetShouldReceiveOwnMessages(should bool)
- func (b *PostgreSQLBroker) Subscribe(topic shared.PubSubChannel) (<-chan map[string]interface{}, error)
- type PostgreSQLMessage
Constants ¶
This section is empty.
Variables ¶
var Module = fx.Options( fx.Provide(NewPgxConnPool), fx.Provide(NewGormDB), fx.Provide(fx.Annotate(NewPostgreSQLBroker, fx.As(new(shared.PubSubBroker)))), )
Functions ¶
func GetMigrationVersionWithDB ¶
GetMigrationVersionWithDB returns the current migration version using an existing GORM database instance
func IsDuplicateKeyError ¶
func NewPgxConnPool ¶
func NewPgxConnPool(cfg PoolConfig) *pgxpool.Pool
func RunMigrations ¶
RunMigrations runs all pending database migrations using an existing GORM database instance
Types ¶
type ListeningConnection ¶
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{}