database

package
v0.3.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DialectPostgres = "postgres"
)

Variables

This section is empty.

Functions

func GetDriverAndName

func GetDriverAndName(dataSourceAddress string) (dsd, dsn string, err error)

func IsConnected

func IsConnected(ctx context.Context, db *sql.DB) error

func LoadDriver

func LoadDriver(dataSourceAddress string) (drvDialect string, drv *sql.DB, err error)

func NewStatsCollectorWith

func NewStatsCollectorWith(db *sql.DB) prometheus.Collector

func Wait

func Wait(ctx context.Context, drv *sql.DB) (err error)

Types

type Embedded

type Embedded struct{}

func (Embedded) GetDriver

func (Embedded) GetDriver(ctx context.Context) (string, string, *sql.DB, error)

func (Embedded) Run

func (Embedded) Run(ctx context.Context) error

type ListenHandler

type ListenHandler interface {
	// Channels returns the name list of multiple channels to establish.
	Channels() []string

	// Handle handles the payload according to the given channel.
	Handle(ctx context.Context, channel, payload string)
}

ListenHandler holds the operations for the database listen handler.

type Listener

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

Listener subscribes the database listen channel and handle the event.

func NewListener

func NewListener(dataSourceAddress string, opts ...Option) (*Listener, error)

NewListener create database listener with options.

func (*Listener) Register

func (l *Listener) Register(handler ListenHandler) error

Register listens the channel returns by the given handler and handles by the given handler if event received.

func (*Listener) Start

func (l *Listener) Start(ctx context.Context) error

Start setups a database listener to subscribe the established channels, and stops when the given context is done.

type Option

type Option func(*Listener)

Option is a function that configures a listener.

func WithReconnectInterval

func WithReconnectInterval(min, max time.Duration) Option

WithReconnectInterval can be used to set the min and max reconnect interval.

Jump to

Keyboard shortcuts

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