MySqlConnection

MySQL connection using the official driver.

Implements: IReferenceable, IConfigurable, IOpenable

Description

The MySqlConnection class allows you to create a connection to a MySQL database using a plain driver.

Configuration parameters

connection(s):

  • discovery_key: (optional) 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) key to retrieve the credentials from ICredentialStore
  • username: username
  • password: user’s password

options:

  • connect_timeout: (optional) number of milliseconds to wait before timing out when connecting a new client (default: 0)

Note: the options below are currently not supported.

  • 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

Fields

_connection

The MySQL connection pool object.

connection_: any

_connectionResolver

The connection resolver.

connectionResolver_: MySqlConnectionResolver

_databaseName

The MySQL database name.

databaseName_: string

_logger

The logger.

logger_: CompositeLogger

_options

The configuration options.

options_: ConfigParams

Instance methods

close

Closes the component and frees used resources.

Future close(IContext? context) async

  • context: IContext - (optional) a context to trace execution through a call chain.

configure

Configures the component by passing configuration parameters.

void configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

getConnection

Gets the connection.

mysql_driver.MySqlConnection? getConnection()

  • returns: connection to a MySQL database

getDatabaseName

Gets the database name

String? getDatabaseName()

  • returns: string - database name

isOpen

Checks if the component is opened.

bool isOpen()

  • returns: boolean - True if the component has been opened and False otherwise.

open

Opens the component.

Future open(IContext? context) async

  • context: IContext - (optional) a context to trace execution through a call chain.

setReferences

Sets references to dependent components.

void setReferences(IReferences references)

  • references: IReferences - references to locate the component dependencies.