DataSource
ldbc.DataSource
A factory for database connections that provides connections as managed resources.
DataSource is a fundamental abstraction in ldbc that encapsulates the logic for establishing database connections. It provides a uniform interface for obtaining connections regardless of the underlying implementation (JDBC, native MySQL protocol, etc.).
Implementations of this trait are responsible for:
- Connection pooling (if applicable)
- Connection configuration and initialization
- Resource lifecycle management
- Error handling during connection establishment
The connections are provided as cats.effect.Resource instances, ensuring that:
- Connections are properly initialized before use
- Resources are cleaned up when no longer needed
- Connection leaks are prevented through automatic resource management
Type parameters
- F
-
the effect type (e.g., IO, Future, etc.) that wraps the operations
Attributes
- See also
-
ldbc.connector.MySQLDataSource for the pure Scala implementation
jdbc.connector.MySQLDataSource for the JDBC-based implementation
- Example
-
// Using a DataSource to execute database operations val dataSource: DataSource[IO] = MySQLDataSource.fromConfig(config) val result: IO[List[User]] = dataSource.getConnection.use { connection => sql"SELECT * FROM users".query[User].to[List].run(connection) }
- Source
- DataSource.scala
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
Members list
In this article