-
Notifications
You must be signed in to change notification settings - Fork 20
Using IDB
This object uses a builder pattern
class App {
public static void main() {
DatabaseOptions options = DatabaseOptions.builder().mysql("user", "pass", "db", "localhost:3306").build()
}
}
This sets all the basic properties of IDB that is generic to JDBC / Asynchronous Query Execution
This options object is passed to the createHikariDatabase, which takes a DatabaseOptions setting, as well as settings to control connection pooling.
Create a PooledDatabaseOptions
object, which then requires a DatabaseOptions
object, and create the Database API.
Example:
class App {
public static void main() {
DatabaseOptions options = DatabaseOptions.builder().mysql("user", "pass", "db", "localhost:3306").build()
Database db = PooledDatabaseOptions.builder().options(options).createHikariDatabase();
DB.setGlobalDatabase(db);
}
}
Then you may use any of the static API's in the DB class around your app, and they will use the global database instance.
If you prefer a dependency injection approach, simply pass your Database instance.
See IDB API for API Documentation
When your app is shutting down, it is important that you call database.close()
or DB.close()
, to shut down the asynchronous thread pools and flush them to finish.
It is recommended you close your pool AFTER everything that might enqueue queries as part of your shut down process has finished shutting down.