0

I'm trying the Play framework with Scala and Slick for data access.

I'm playing with the play-scala-intro example app. I'm trying to set up my own database instead of using the bundled in memory H2 database.

I can't figure out how to specify the path to the database file.

If the code in application.conf reads:

  slick.dbs.default.db.url="jdbc:sqlite:/test.db"
  slick.dbs.default.db.driver="org.sqlite.JDBC"

where should my test.db file be placed?

Does that mean the test.db file should be in the home directory of the web app, meaning the root play-scala-intro dir, or the app/assets dir?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Duncan
  • 151
  • 1
  • 4

1 Answers1

0

I'd say storing your database in Java resources (and that's where assets will end up) doesn't sound like a good idea to me. I would be surprised if nothing went wrong during e.g. writing to DB.

It would be better to have it in the same directory as JAR, and even better set some defaults and let them be overridden:

database.location="test.db"
database.location=${?DBLOCATION}

slick.dbs.default.db.url="jdbc:sqlite:"${database.location}

This should assume that your database is names test.db and placed in your working directory (see: https://stackoverflow.com/a/21061029/1305121). It can be overridden using environment variable DBLOCATION like:

export DBLOCATION="/tmp/my/database.db"
# run Play application
Community
  • 1
  • 1
Mateusz Kubuszok
  • 24,995
  • 4
  • 42
  • 64