SQLite
Use SQLite as the JobRunr StorageProvider - driver dependency, configuration, and table creation.
On this page
JobRunr stores all background jobs in SQLite through the SqLiteStorageProvider. JobRunr is tested against sqlite-jdbc version 3.47.2.0.
NoteSQLite is an excellent embedded database - it ships with Android, iOS, macOS and most Linux distributions, which makes it a natural fit for mobile and desktop applications. It is serverless and file-based by design though, so there is no cluster mode: background job servers on different machines cannot share a SQLite database.
Add the driver dependency
Add the SQLite JDBC driver to your project. The latest version is on Maven Central.
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version><!-- latest version --></version>
</dependency>
implementation 'org.xerial:sqlite-jdbc' // version omitted, use latest
Configuration
If you use a framework starter, JobRunr automatically detects your existing DataSource - configure your database the usual way and you are done.
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:sqlite:./data/mydb.sqlite");
DataSource dataSource = new HikariDataSource(config);
JobRunr.configure()
.useStorageProvider(SqlStorageProviderFactory.using(dataSource))
.useBackgroundJobServer()
.initialize();
datasources:
default:
url: jdbc:sqlite:./data/mydb.sqlite
driver-class-name: org.sqlite.JDBC
# requires the io.quarkiverse.jdbc:quarkus-jdbc-sqlite extension
quarkus.datasource.db-kind=sqlite
quarkus.datasource.jdbc.url=jdbc:sqlite:./data/mydb.sqlite
spring.datasource.url=jdbc:sqlite:./data/mydb.sqlite
spring.datasource.driver-class-name=org.sqlite.JDBC
Creating the tables
By default JobRunr creates its tables automatically. If you want to create them yourself, use the DatabaseCreator or generate the SQL scripts with migration type sqlite. See Setting up an SQL database.
Next steps
- Keep the tables in their own schema: JobRunr can prefix every table it creates. See table prefix and schema.
- Using more than one database? Tell JobRunr which one it should use. See multiple databases in one application.
- Build the
StorageProvideryourself: Useful for an explicit table prefix,DatabaseOptions, or a provider JobRunr does not pick up automatically. See configuring the StorageProvider yourself.
Looking for another database? Back to the Storage overview.
