Connection Supplier
Allows access to an SQL database.
Supported RDBMS
Currently, PostgreSQL is the best experience you can have. H2 was also tested, but requires the PostgreSQL compatibility mode. Whether the H2 database runs in-memory, in a file, or as a server is up to you, see the available connection modes for more details.
An H2 JDBC URL might look like this: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;DEFAULT_NULL_ORDERING=HIGH
DB_CLOSE_DELAY=-1
prevents the database from being lost when all connections are closed, while MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;DEFAULT_NULL_ORDERING=HIGH
is required.
See the H2 compatibility modes for more details.
Using H2 is only recommended if you absolutely do not want to/cant install the PostgreSQL server, the PostgreSQL driver has a far superior quality, larger feature set and has full syntax support.
Usage
First, register your instance as a service with @BService.
With Flyway (Recommended)
You can run this code after initializing your service:
Flyway.configure()
.dataSource(source)
.schemas("bc")
.locations("bc_database_scripts")
.validateMigrationNaming(true)
.loggers("slf4j")
.load()
.migrate()
This will run all the migration scripts required to set up your database
Manual initialization
You will have to create a bc
schema, and run these scripts in chronological order.
See also
@InterfacedService