Reputation: 20222
I am trying to create my first project using Play.
I can see that in application.conf
there is a some database configuration code.
# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
# db.default.driver=org.h2.Driver
# db.default.url="jdbc:h2:mem:play"
# db.default.username=sa
# db.default.password=""
Does that mean by any chance that play comes with a prepackages database, as Rails comes with SQLite?
In the introduction to Play from here https://www.playframework.com/, he doesn't write any code for adding a database.
What is the above code useful for?
Upvotes: 1
Views: 309
Reputation: 2804
It is just an example of how to configure a DB connection.
The default application is using a memory database as SQLite, but in this case it is used H2.
If you check the file build.sbt
you will find the dependency for this DB. But you can define any other database you may need here.
e.g.: If you need to connect to a postgreSQL DB you could use the example you may find in this link:
db.customers.driver=org.postgresql.Driver
db.customers.url="jdbc:postgresql://database.example.com/playdb"
But you will have to define the dependency in build.sbt
. Something like:
libraryDependencies += "org.postgresql" % "postgresql" % "9.4-1200-jdbc41
Upvotes: 4
Reputation: 8901
When you add the jdbc
library dependency to your Play project, that will also add the H2 database, which is somewhat like the Java-based equivalent to SQLite in the Rails context, in that it's typically used locally with in-memory or file-based databases during development (not that you can't use it in production also.) In particular it's quite common to test using an in-memory H2 database, even if you use PostgreSQL etc in production.
The example settings in Play's default application.conf
are intended to get you started by providing the basic configuration for an in-memory H2 DB, namely which driver class JDBC should use (put on the classpath by Play) and the database connection URL.
Upvotes: 3