mirror of
https://github.com/jlengrand/exposed-wiki.git
synced 2026-03-10 08:11:18 +00:00
679 B
679 B
Working with DataBase and DataSource
Every database access using Expose is starting by obtaining a connection and creating a transaction.
To get a connection:
val db = Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver")
It is also possible to provide javax.sql.DataSource for advanced behaviors such as connection pooling:
val db = Database.connect(dataSource)
- Note: Starting Exposed 0.10 executing this code more than once per db will create leaks in your application, hence it is recommended to store it for later use.
For example:
object DbSettings {
val db by lazy {
Database.connect(...)
}
}