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 ¶
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" )
const ( // EnvID defines the rdb package base environment variable name. EnvID = slate.EnvID + "_RDB" )
const ( // UnknownDialectType defines the value to be used to // identify an unknown dialect. UnknownDialectType = "unknown" )
Variables ¶
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) )
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.
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 ¶
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
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.