Sid
Sid

Reputation: 1719

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

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.

Upvotes: 1

Views: 514

Answers (1)

Sid
Sid

Reputation: 1719

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.

Upvotes: 1

Related Questions