Skip to content

Add DataSource support for JDBC integration #1424

@zaleslaw

Description

@zaleslaw

May we have such override?

public fun DataFrame.Companion.readSqlTable(
    dataSource: DataSource,
): AnyFrame {
    dataSource.connection.use { connection ->
        return readSqlTable(connection, ...)
    }
}

It looks like DataSource is a preferred API to use.
It looks like the recommended way to create SQL DB connection in production is using HikariCP, at least it's something LLM yieds for me:

fun dataSource(): HikariDataSource {
    val cfg = HikariConfig().apply {
        jdbcUrl = "jdbc:postgresql://localhost:5432/appdb?sslmode=disable"
        username = "app"
        password = "secret"
        ...
    }
    return HikariDataSource(cfg)
}

So, when we have the data source, we have javax.sql.DataSource , which is welcomed i.e. by exposed:

fun DataSource.listActive(): List<String> {
    Database.connect(this)
    return transaction {
        ...
    }
}

It would be nice to be able to use this dataSource in any possible DB wrapper, it will allow this design to converge.

Metadata

Metadata

Assignees

Labels

databasesJDBC related issuesdocumentationImprovements or additions to documentation (not KDocs)enhancementNew feature or requestexamplesSomething related to the examples

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions