database

package
v1.0.0-rc.8 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Copyright (C) 2025 l3montree GmbH

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	PolicyChange = "policyChange"
)

Variables

This section is empty.

Functions

func GetMigrationVersionWithDB

func GetMigrationVersionWithDB(gormDB *gorm.DB) (uint, bool, error)

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

func IsDuplicateKeyError

func IsDuplicateKeyError(err error) bool

func NewConnection

func NewConnection(host, user, password, dbname, port string) (*gorm.DB, error)

func RunMigrationsWithDB

func RunMigrationsWithDB(gormDB *gorm.DB) error

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

Types

type Broker

type Broker interface {
	Publish(ctx context.Context, message Message) error
	Subscribe(topic Channel) (<-chan map[string]any, error)
}

func BrokerFactory

func BrokerFactory() (Broker, error)

type Channel

type Channel string

type JSONB

type JSONB map[string]any

func JSONbFromStruct

func JSONbFromStruct(m any) (JSONB, error)

func MustJSONBFromStruct

func MustJSONBFromStruct(m any) JSONB

func (*JSONB) Scan

func (jsonField *JSONB) Scan(value any) error

Scan Unmarshal

func (JSONB) Value

func (jsonField JSONB) Value() (driver.Value, error)

Value Marshal

type Message

type Message interface {
	GetChannel() Channel
	GetPayload() map[string]any
}

type PageInfo

type PageInfo struct {
	Total    int64 `json:"total"`
	PageSize int   `json:"pageSize"`
	Page     int   `json:"page"`
}

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(user, password, host, port, dbname string) (*PostgreSQLBroker, error)

NewPostgreSQLBroker creates a new PostgreSQL broker

func (*PostgreSQLBroker) Close

func (b *PostgreSQLBroker) Close() error

Close stops the broker and cleans up resources

func (*PostgreSQLBroker) GetActiveTopics

func (b *PostgreSQLBroker) GetActiveTopics() []Channel

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 Message) error

Publish implements the Broker interface

func (*PostgreSQLBroker) SetShouldReceiveOwnMessages

func (b *PostgreSQLBroker) SetShouldReceiveOwnMessages(should bool)

func (*PostgreSQLBroker) Subscribe

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

Subscribe implements the Broker interface

type PostgreSQLMessage

type PostgreSQLMessage struct {
	ID        string                 `json:"id"`
	Channel   Channel                `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() Channel

func (PostgreSQLMessage) GetPayload

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

type SimpleMessage

type SimpleMessage struct {
	Channel Channel
	Payload map[string]any
}

func NewSimpleMessage

func NewSimpleMessage(channel Channel, payload map[string]any) *SimpleMessage

NewSimpleMessage creates a new SimpleMessage instance.

func (SimpleMessage) GetChannel

func (m SimpleMessage) GetChannel() Channel

func (SimpleMessage) GetPayload

func (m SimpleMessage) GetPayload() map[string]any

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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