A DataSource implementation for MySQL connections using the pure Scala MySQL wire protocol.
This DataSource provides connection pooling capabilities and manages MySQL connections with support for SSL, authentication, prepared statements, and various connection options. It also supports lifecycle hooks that can be executed before and after connection acquisition.
Type parameters
- A
-
the type of value returned by the before hook
- F
-
the effect type (e.g., IO, Task) that must have Async, Network, Console, Hashing, and UUIDGen capabilities
Value parameters
- after
-
optional hook to execute after a connection is used
- allowPublicKeyRetrieval
-
whether to allow retrieval of RSA public keys from the server
- before
-
optional hook to execute before a connection is acquired
- database
-
the default database to use upon connection
- databaseTerm
-
the database terminology to use (CATALOG or SCHEMA)
- debug
-
whether to enable debug logging for connections
- host
-
the hostname or IP address of the MySQL server
- password
-
the password for authenticating with the MySQL server
- port
-
the port number on which the MySQL server is listening
- readTimeout
-
the timeout duration for read operations
- socketOptions
-
socket-level options for the TCP connection
- ssl
-
the SSL configuration for secure connections
- tracer
-
optional OpenTelemetry tracer for distributed tracing
- useCursorFetch
-
whether to use cursor-based fetching for result sets
- useServerPrepStmts
-
whether to use server-side prepared statements
- user
-
the username for authenticating with the MySQL server
Attributes
- Example
-
val dataSource = MySQLDataSource[IO, Unit]( host = "localhost", port = 3306, user = "myuser", password = Some("mypassword"), database = Some("mydatabase"), ssl = SSL.Trusted ) // With lifecycle hooks val dataSourceWithHooks = dataSource .withBefore(conn => IO.println("Connection acquired")) .withAfter((_, conn) => IO.println("Connection released"))
- Companion
- object
- Source
- MySQLDataSource.scala
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait DataSource[F]class Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
Creates a new connection resource from this DataSource.
Creates a new connection resource from this DataSource.
The connection is managed as a resource, ensuring proper cleanup when the resource is released. If before/after hooks are configured, they will be executed during the connection lifecycle.
Attributes
- Returns
-
a Resource that manages a MySQL connection
- Definition Classes
- Source
- MySQLDataSource.scala
Sets whether to allow retrieval of RSA public keys from the server. This is required for certain authentication plugins when SSL is not used.
Sets whether to allow retrieval of RSA public keys from the server. This is required for certain authentication plugins when SSL is not used.
Value parameters
- newAllowPublicKeyRetrieval
-
true to allow public key retrieval
Attributes
- Returns
-
a new MySQLDataSource with the updated setting
- Source
- MySQLDataSource.scala
Sets the default database to use upon connection.
Sets the default database to use upon connection.
Value parameters
- newDatabase
-
the database name
Attributes
- Returns
-
a new MySQLDataSource with the updated database
- Source
- MySQLDataSource.scala
Sets the database terminology to use. MySQL traditionally uses CATALOG, but this can be configured.
Sets the database terminology to use. MySQL traditionally uses CATALOG, but this can be configured.
Value parameters
- newDatabaseTerm
-
the database term (CATALOG or SCHEMA)
Attributes
- Returns
-
a new MySQLDataSource with the updated database term
- Source
- MySQLDataSource.scala
Enables or disables debug logging for connections.
Enables or disables debug logging for connections.
Value parameters
- newDebug
-
true to enable debug logging, false to disable
Attributes
- Returns
-
a new MySQLDataSource with the updated debug setting
- Source
- MySQLDataSource.scala
Sets the hostname or IP address of the MySQL server.
Sets the hostname or IP address of the MySQL server.
Value parameters
- newHost
-
the hostname or IP address
Attributes
- Returns
-
a new MySQLDataSource with the updated host
- Source
- MySQLDataSource.scala
Sets the password for MySQL authentication.
Sets the password for MySQL authentication.
Value parameters
- newPassword
-
the password
Attributes
- Returns
-
a new MySQLDataSource with the updated password
- Source
- MySQLDataSource.scala
Sets the port number for the MySQL connection.
Sets the port number for the MySQL connection.
Value parameters
- newPort
-
the port number (typically 3306)
Attributes
- Returns
-
a new MySQLDataSource with the updated port
- Source
- MySQLDataSource.scala
Sets the timeout duration for read operations.
Sets the timeout duration for read operations.
Value parameters
- newReadTimeout
-
the read timeout duration, or Duration.Inf for no timeout
Attributes
- Returns
-
a new MySQLDataSource with the updated read timeout
- Source
- MySQLDataSource.scala
Sets the SSL configuration for secure connections.
Sets the SSL configuration for secure connections.
Value parameters
- newSSL
-
the SSL configuration (None, Trusted, or System)
Attributes
- Returns
-
a new MySQLDataSource with the updated SSL setting
- Source
- MySQLDataSource.scala
Sets socket-level options for the TCP connection.
Sets socket-level options for the TCP connection.
Value parameters
- newSocketOptions
-
list of socket options to apply
Attributes
- Returns
-
a new MySQLDataSource with the updated socket options
- Source
- MySQLDataSource.scala
Sets the OpenTelemetry tracer for distributed tracing.
Sets the OpenTelemetry tracer for distributed tracing.
Value parameters
- newTracer
-
the tracer instance
Attributes
- Returns
-
a new MySQLDataSource with the updated tracer
- Source
- MySQLDataSource.scala
Sets whether to use cursor-based fetching for result sets. This can improve memory usage for large result sets.
Sets whether to use cursor-based fetching for result sets. This can improve memory usage for large result sets.
Value parameters
- newUseCursorFetch
-
true to enable cursor-based fetching
Attributes
- Returns
-
a new MySQLDataSource with the updated setting
- Source
- MySQLDataSource.scala
Sets whether to use server-side prepared statements. Server-side prepared statements can improve performance for repeated queries.
Sets whether to use server-side prepared statements. Server-side prepared statements can improve performance for repeated queries.
Value parameters
- newUseServerPrepStmts
-
true to enable server-side prepared statements
Attributes
- Returns
-
a new MySQLDataSource with the updated setting
- Source
- MySQLDataSource.scala
Sets the username for MySQL authentication.
Sets the username for MySQL authentication.
Value parameters
- newUser
-
the username
Attributes
- Returns
-
a new MySQLDataSource with the updated user
- Source
- MySQLDataSource.scala
Adds an after hook that will be executed when a connection is released.
Adds an after hook that will be executed when a connection is released.
The after hook receives the value returned by the before hook (if any) and the connection, allowing cleanup or finalization tasks.
Value parameters
- after
-
the function to execute after using a connection
Attributes
- Returns
-
a new MySQLDataSource with the after hook configured
- Source
- MySQLDataSource.scala
Adds a before hook that will be executed when a connection is acquired.
Adds a before hook that will be executed when a connection is acquired.
The before hook receives the connection and can perform initialization tasks or return a value that will be passed to the after hook.
Type parameters
- B
-
the type of value returned by the before hook
Value parameters
- before
-
the function to execute before using a connection
Attributes
- Returns
-
a new MySQLDataSource with the before hook configured
- Source
- MySQLDataSource.scala
Adds both before and after hooks for connection lifecycle management.
Adds both before and after hooks for connection lifecycle management.
This is a convenience method that combines withBefore and withAfter, allowing you to set up both hooks in a single call. The before hook is executed when a connection is acquired, and the after hook is executed when it's released.
Type parameters
- B
-
the type of value returned by the before hook
Value parameters
- after
-
the function to execute after using a connection
- before
-
the function to execute before using a connection
Attributes
- Returns
-
a new MySQLDataSource with both hooks configured
- Example
-
val dataSourceWithHooks = dataSource.withBeforeAfter( before = conn => IO.println("Starting transaction").as(System.currentTimeMillis), after = (startTime, conn) => IO.println(s"Completed in ${System.currentTimeMillis - startTime}ms") )
- Source
- MySQLDataSource.scala
Givens
Givens
Attributes
- Source
- MySQLDataSource.scala