MySQLDataSource

ldbc.connector.MySQLDataSource
See theMySQLDataSource companion object
final case class MySQLDataSource[F[_], A](host: String, port: Int, user: String, logHandler: Option[LogHandler[F]], password: Option[String], database: Option[String], debug: Boolean, ssl: SSL, socketOptions: List[SocketOption], readTimeout: Duration, allowPublicKeyRetrieval: Boolean, databaseTerm: Option[DatabaseTerm], tracer: Option[Tracer[F]], useCursorFetch: Boolean, useServerPrepStmts: Boolean, before: Option[(Connection[F]) => F[A]], after: Option[(A, Connection[F]) => F[Unit]])(implicit evidence$1: Async[F], evidence$2: Network[F], evidence$3: Console[F], evidence$4: Hashing[F], evidence$5: UUIDGen[F]) extends DataSource[F]

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

logHandler

optional handler for logging connection and query events

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 Serializable
trait Product
trait Equals
trait DataSource[F]
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def getConnection: Resource[F, Connection[F]]

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
def setAllowPublicKeyRetrieval(newAllowPublicKeyRetrieval: Boolean): MySQLDataSource[F, A]

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
def setDatabase(newDatabase: String): MySQLDataSource[F, A]

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
def setDatabaseTerm(newDatabaseTerm: DatabaseTerm): MySQLDataSource[F, A]

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
def setDebug(newDebug: Boolean): MySQLDataSource[F, A]

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
def setHost(newHost: String): MySQLDataSource[F, A]

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
def setPassword(newPassword: String): MySQLDataSource[F, A]

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
def setPort(newPort: Int): MySQLDataSource[F, A]

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
def setReadTimeout(newReadTimeout: Duration): MySQLDataSource[F, A]

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
def setSSL(newSSL: SSL): MySQLDataSource[F, A]

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
def setSocketOptions(newSocketOptions: List[SocketOption]): MySQLDataSource[F, A]

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
def setTracer(newTracer: Tracer[F]): MySQLDataSource[F, A]

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
def setUseCursorFetch(newUseCursorFetch: Boolean): MySQLDataSource[F, A]

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
def setUseServerPrepStmts(newUseServerPrepStmts: Boolean): MySQLDataSource[F, A]

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
def setUser(newUser: String): MySQLDataSource[F, A]

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
def withAfter(after: (A, Connection[F]) => F[Unit]): MySQLDataSource[F, A]

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
def withBefore[B](before: (Connection[F]) => F[B]): MySQLDataSource[F, B]

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
def withBeforeAfter[B](before: (Connection[F]) => F[B], after: (B, Connection[F]) => F[Unit]): MySQLDataSource[F, B]

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

Inherited methods

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product

Givens

Givens

Attributes

Source
MySQLDataSource.scala