rdb

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package rdb define instances an application provider that publicise an interface to a set of services used to connect and interact with a relational database.

Index

Constants

View Source
const (
	// ID defines the id to be used as the container
	// registration id of a relational database connection pool instance,
	// and as a base id of all other relational database package instances
	// registered in the application container.
	ID = slate.ID + ".rdb"

	// ConfigID defines the id to be used as the container
	// registration id of the relational database connection configuration
	// instance.
	ConfigID = ID + ".config"

	// DialectStrategyTag defines the tag to be assigned to all
	// container relational database dialect strategies.
	DialectStrategyTag = ID + ".dialect.strategy"

	// DialectFactoryID defines the id to be used as the
	// container registration id of the relational database connection dialect
	// factory instance.
	DialectFactoryID = ID + ".dialect.factory"

	// ConnectionFactoryID defines the id to be used as the container
	// registration id of the connection factory instance.
	ConnectionFactoryID = ID + ".connection.factory"

	// ConnectionPrimaryID defines the id to be used as the container
	// registration id of primary relational database instance.
	ConnectionPrimaryID = ID + ".connection.primary"
)
View Source
const (
	// EnvID defines the rdb package base environment variable name.
	EnvID = slate.EnvID + "_RDB"
)
View Source
const (
	// UnknownDialectType defines the value to be used to
	// identify an unknown dialect.
	UnknownDialectType = "unknown"
)

Variables

View Source
var (
	// Primary contains the name given to the primary connection.
	Primary = env.String(EnvID+"_PRIMARY", "primary")

	// ConnectionsConfigPath contains the configuration path that holds the
	// relational database connection configurations.
	ConnectionsConfigPath = env.String(EnvID+"_CONNECTIONS_CONFIG_PATH", "slate.rdb.connections")

	// ObserveConfig defines the connection factory cfg observing flag
	// used to register in the cfg object an observer of the connection
	// cfg entries list, so it can reset the connections pool.
	ObserveConfig = env.Bool(EnvID+"_OBSERVE_CONFIG", true)
)
View Source
var (
	// ErrConfigNotFound defines an error that signal that the
	// configuration to the requested database connection was not found.
	ErrConfigNotFound = fmt.Errorf("database config not found")

	// ErrUnknownDialect defines an error that signal that the
	// requested database connection configured dialect is unknown.
	ErrUnknownDialect = fmt.Errorf("unknown database dialect")
)

Functions

This section is empty.

Types

type ConnectionFactory added in v0.20.0

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

ConnectionFactory is a database connection generator.

func (*ConnectionFactory) Create added in v0.20.0

func (f *ConnectionFactory) Create(
	cfg config.IConfig,
	gormCfg *gorm.Config,
) (*gorm.DB, error)

Create execute the process of the connection creation based on the base configuration defined by the given name of the connection, and apply the extra connection cfg also given as arguments.

type DialectFactory

type DialectFactory []IDialectStrategy

DialectFactory defines an object that will generate a database dialect interface based on a registered list of dialect generation strategies.

func (DialectFactory) Get

func (f DialectFactory) Get(
	cfg config.IConfig,
) (gorm.Dialector, error)

Get generates a new connection dialect interface defined by the configuration parameters stored in the configuration partial marked by the given name.

func (*DialectFactory) Register

func (f *DialectFactory) Register(
	strategy IDialectStrategy,
) error

Register will register a new dialect factory strategy to be used on requesting to create a dialect.

type IConnectionFactory

type IConnectionFactory interface {
	Create(cfg config.IConfig, gormCfg *gorm.Config) (*gorm.DB, error)
}

IConnectionFactory defines the interface of a connection factory instance.

func NewConnectionFactory added in v0.16.0

func NewConnectionFactory(
	dialectFactory IDialectFactory,
) (IConnectionFactory, error)

NewConnectionFactory will instantiate a new relational database connection factory instance.

type IConnectionPool added in v0.20.0

type IConnectionPool interface {
	Get(name string, gormCfg *gorm.Config) (*gorm.DB, error)
}

IConnectionPool defines the interface of a connection pool instance.

func NewConnectionPool added in v0.20.0

func NewConnectionPool(
	cfg config.IManager,
	factory IConnectionFactory,
) (IConnectionPool, error)

NewConnectionPool will instantiate a new relational database connection pool instance.

type IDialectFactory

type IDialectFactory interface {
	Register(strategy IDialectStrategy) error
	Get(config.IConfig) (gorm.Dialector, error)
}

IDialectFactory defines the interface of a connection dialect instance.

func NewDialectFactory added in v0.20.0

func NewDialectFactory() IDialectFactory

NewDialectFactory will instantiate a new relational database dialect factory instance.

type IDialectStrategy

type IDialectStrategy interface {
	Accept(config.IConfig) bool
	Get(config.IConfig) (gorm.Dialector, error)
}

IDialectStrategy defines the interface to a gorm rdb dialect instantiation strategy, based on a configuration.

type Provider

type Provider struct{}

Provider defines the slate.rdb module service provider to be used on the application initialization to register the relational database services.

func (Provider) Boot

func (p Provider) Boot(
	container slate.IContainer,
) (e error)

Boot will start the rdb package

func (Provider) Register

func (p Provider) Register(
	container slate.IContainer,
) error

Register will register the rdb package instances in the application container

Directories

Path Synopsis
Package dialect defines the base types and structures of all relational database dialect functionalities.
Package dialect defines the base types and structures of all relational database dialect functionalities.

Jump to

Keyboard shortcuts

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