connect

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultConnectTimeout = 1000
	DefaultIdleTimeout    = 10000
	DefaultMaxPoolSize    = 3
	DefaultRetriesCount   = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MySqlConnection added in v1.0.1

type MySqlConnection struct {

	// The logger.
	Logger *clog.CompositeLogger
	// The connection resolver.
	ConnectionResolver *MySqlConnectionResolver
	// The configuration options.
	Options *cconf.ConfigParams
	// The MySQL connection pool object.
	Connection *sql.DB
	// The MySQL database name.
	DatabaseName string
	// contains filtered or unexported fields
}

MySQL connection using plain driver.

By defining a connection and sharing it through multiple persistence components you can reduce number of used database connections.

Configuration parameters
	- connection(s):
		- discovery_key:        (optional) a key to retrieve the connection from IDiscovery
		- host:                 host name or IP address
		- port:                 port number (default: 27017)
		- uri:                  resource URI or connection string with all parameters in it
	- credential(s):
		- store_key:            (optional) a key to retrieve the credentials from ICredentialStore
		- username:             user name
		- password:             user password
	- options:
		- connect_timeout:      (optional) number of milliseconds to wait before timing out when connecting a new client (default: 0)
		- idle_timeout:         (optional) number of milliseconds a client must sit idle in the pool and not be checked out (default: 10000)
		- max_pool_size:        (optional) maximum number of clients the pool should contain (default: 10)

References
	- *:logger:*:*:1.0           (optional) ILogger components to pass log messages
	- *:discovery:*:*:1.0        (optional) IDiscovery services
	- *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials

func NewMySqlConnection added in v1.0.1

func NewMySqlConnection() *MySqlConnection

NewMySqlConnection creates a new instance of the connection component.

func (*MySqlConnection) Close added in v1.0.1

func (c *MySqlConnection) Close(ctx context.Context, correlationId string) error

Close component and frees used resources.

Parameters:
	- ctx context.Context
	- correlationId (optional) transaction id to trace execution through call chain.
Returns: error or nil no errors occurred

func (*MySqlConnection) Configure added in v1.0.1

func (c *MySqlConnection) Configure(ctx context.Context, config *cconf.ConfigParams)

Configure component by passing configuration parameters.

Parameters:
	- ctx context.Context
	- config configuration parameters to be set.

func (*MySqlConnection) GetConnection added in v1.0.1

func (c *MySqlConnection) GetConnection() *sql.DB

func (*MySqlConnection) GetDatabaseName added in v1.0.1

func (c *MySqlConnection) GetDatabaseName() string

func (*MySqlConnection) IsOpen added in v1.0.1

func (c *MySqlConnection) IsOpen() bool

IsOpen checks if the component is opened.

Returns true if the component has been opened and false otherwise.

func (*MySqlConnection) Open added in v1.0.1

func (c *MySqlConnection) Open(ctx context.Context, correlationId string) error

Open the component. Parameters:

  • ctx context.Context
  • correlationId (optional) transaction id to trace execution through call chain.
  • Return error or nil no errors occurred.

func (*MySqlConnection) SetReferences added in v1.0.1

func (c *MySqlConnection) SetReferences(ctx context.Context, references cref.IReferences)

SetReferences references to dependent components.

Parameters:
	- ctx context.Context
	- references references to locate the component dependencies.

type MySqlConnectionResolver added in v1.0.1

type MySqlConnectionResolver struct {
	// The connections' resolver.
	ConnectionResolver *cconn.ConnectionResolver
	// The credentials' resolver.
	CredentialResolver *cauth.CredentialResolver
}

Helper class that resolves MySQL connection and credential parameters, validates them and generates a connection URI. It is able to process multiple connections to MySQL cluster nodes.

Configuration parameters:
	- connection(s):
		- discovery_key:               (optional) a key to retrieve the connection from IDiscovery
		- host:                        host name or IP address
		- port:                        port number (default: 27017)
		- database:                    database name
		- uri:                         resource URI or connection string with all parameters in it
	- credential(s):
		- store_key:                   (optional) a key to retrieve the credentials from ICredentialStore
		- username:                    user name
		- password:                    user password

References:
	- *:discovery:*:*:1.0             (optional) IDiscovery services
	- *:credential-store:*:*:1.0      (optional) Credential stores to resolve credentials

func NewMySqlConnectionResolver added in v1.0.1

func NewMySqlConnectionResolver() *MySqlConnectionResolver

NewMySqlConnectionResolver creates new connection resolver

Returns: *MySqlConnectionResolver

func (*MySqlConnectionResolver) Configure added in v1.0.1

func (c *MySqlConnectionResolver) Configure(ctx context.Context, config *cconf.ConfigParams)

Configure is configures component by passing configuration parameters.

Parameters:
	- ctx context.Context
	- config *cconf.ConfigParams configuration parameters to be set.

func (*MySqlConnectionResolver) Resolve added in v1.0.1

func (c *MySqlConnectionResolver) Resolve(ctx context.Context, correlationId string) (uri string, err error)

Resolve method are resolves MySql connection URI from connection and credential parameters.

Parameters:
	- ctx context.Context
	- correlationId string (optional) transaction id to trace execution through call chain.
Returns: uri string, err error resolved URI and error, if this occured.

func (*MySqlConnectionResolver) SetReferences added in v1.0.1

func (c *MySqlConnectionResolver) SetReferences(ctx context.Context, references crefer.IReferences)

SetReferences is sets references to dependent components. Parameters:

  • ctx context.Context
  • references crefer.IReferences references to locate the component dependencies.

Jump to

Keyboard shortcuts

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