How do I enable foreign key constraints for SQLite with Dropwizard and JDBI?

500 views Asked by At

I'm using Dropwizard and its JDBI module in order to connect to an SQLite database. I've setup the database so that it has FKs in place, but I still need to tell SQLite to enable its constraints.

I know you can configure it using a properties instance, but I don't see how to make use of that together with the JDBI setup in Dropwizard.

1

There are 1 answers

0
Sid On BEST ANSWER

You need to add the following property to your .yml settings file: foreign_keys: true.

It should look something like this:

database:
  # the name of your JDBC driver
  driverClass: org.sqlite.JDBC

  # the JDBC URL
  url: jdbc:sqlite:databasefile.db

  # any properties specific to your JDBC driver:
  properties:
    foreign_keys: true

After that you should have FK constraint in your SQLite database. You can check out the SQLiteConfig class for more properties.