connect

package
v0.0.1-3 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SqliteConnection

type SqliteConnection struct {

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

SqliteConnection struct help creates new connections to SQLite SQLite 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: 8082)
		- 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:                  (optional) user name
		- password:                  (optional) user password
	- options:
		- max_pool_size:             (optional) maximum connection pool size (default: 2)
		- keep_alive:                (optional) enable connection keep alive in ms, if zero connection are keeped indefinitely (default: 0)
		- connect_timeout:           (optional) connection timeout in milliseconds (default: 5000)
		- socket_timeout:            (optional) socket timeout in milliseconds (default: 360000)
		- auto_reconnect:            (optional) enable auto reconnection (default: true) (Not used)
		- reconnect_interval:        (optional) reconnection interval in milliseconds (default: 1000) (Not used)
		- max_page_size:             (optional) maximum page size (default: 100)
		- replica_set:               (optional) name of replica set
		- ssl:                       (optional) enable SSL connection (default: false) (Not release in this version)
		- auth_source:               (optional) authentication source
		- debug:                     (optional) enable debug output (default: false). (Not used)

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 NewSqliteConnection

func NewSqliteConnection() *SqliteConnection

NewSqliteConnection are creates a new instance of the connection component. Returns *SqliteConnection with default config

func (*SqliteConnection) Close

func (c *SqliteConnection) Close(ctx context.Context) error

Close method is closes component and frees used resources.

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

func (*SqliteConnection) Configure

func (c *SqliteConnection) 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 (*SqliteConnection) GetConnection

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

GetConnection method return work connection object

Returns: *sql.DB

func (*SqliteConnection) GetDatabase

func (c *SqliteConnection) GetDatabase() *sql.DB

GetDatabase method retrun work database object

Returns: *sql.DB

func (*SqliteConnection) GetDatabaseName

func (c *SqliteConnection) GetDatabaseName() string

GetDatabaseName method reruns name of work database

Returns: string

func (*SqliteConnection) IsOpen

func (c *SqliteConnection) IsOpen() bool

IsOpen method is checks if the component is opened.

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

func (*SqliteConnection) Open

func (c *SqliteConnection) Open(ctx context.Context) error

Open method is opens the component.

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

func (*SqliteConnection) SetReferences

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

SetReferences are sets references to dependent components.

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

type SqliteConnectionResolver

type SqliteConnectionResolver struct {
	//The connections resolver.
	ConnectionResolver ccon.ConnectionResolver
	//The credentials resolver.
	CredentialResolver auth.CredentialResolver
}

SqliteConnectionResolver a helper struct that resolves SQLite connection and credential parameters, validates them and generates a connection URI. It is able to process multiple connections to SQLite 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: 8082)
		- 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 NewSqliteConnectionResolver

func NewSqliteConnectionResolver() *SqliteConnectionResolver

NewSqliteConnectionResolver creates new connection resolver

Returns: *SqliteConnectionResolver

func (*SqliteConnectionResolver) Configure

func (c *SqliteConnectionResolver) 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 (*SqliteConnectionResolver) Resolve

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

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

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

func (*SqliteConnectionResolver) SetReferences

func (c *SqliteConnectionResolver) 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