Exposed: How does Database.connect release?

Created on 25 Jul 2017  路  3Comments  路  Source: JetBrains/Exposed

Exposed has a connection pool?
How does Database.connect release?
How to use with HikariCP(or similar to this frame)?

Most helpful comment

I use this code to use HikariCP:

val dataSource : HikariDataSource

constructor()
{
    val url = "jdbc:postgresql://" + props("db.host") + ":" + props("db.port") + "/" + props("db.name")
    Class.forName("org.postgresql.Driver")

    val cfg = HikariConfig()
    cfg.jdbcUrl = url
    cfg.username = props("db.username")
    cfg.password = props("db.password")
    dataSource = HikariDataSource(cfg)
    Database.connect(dataSource)

    logger.info("DB: Connected to $url")
}

All 3 comments

I use this code to use HikariCP:

val dataSource : HikariDataSource

constructor()
{
    val url = "jdbc:postgresql://" + props("db.host") + ":" + props("db.port") + "/" + props("db.name")
    Class.forName("org.postgresql.Driver")

    val cfg = HikariConfig()
    cfg.jdbcUrl = url
    cfg.username = props("db.username")
    cfg.password = props("db.password")
    dataSource = HikariDataSource(cfg)
    Database.connect(dataSource)

    logger.info("DB: Connected to $url")
}

@msrd0 your code just init a HikariCP instance, but not related to destructor.
i.g. in web app. pre request a thread call ?

transaction {
        logger.addLogger(StdOutSqlLogger)
        ...
    }

all request use just one connection?

I remember I've read once that Exposed closes all connections after the transactions, which means that they are returned to the HikariCP pool. #122 and #123 might be interesting.

I am executing this on the start of every program and use the same instance until the program finishes. I do not see any reason for a destructor, but maybe I got you wrong?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kszymanski85 picture kszymanski85  路  4Comments

quangIO picture quangIO  路  5Comments

hannesstruss picture hannesstruss  路  5Comments

BugsBunnyBR picture BugsBunnyBR  路  3Comments

power721 picture power721  路  3Comments