Skip to content

Commit

Permalink
Added documentation for DatabaseUrlDataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
jkutner authored and szeiger committed Aug 13, 2015
1 parent 9725b41 commit c44e9c8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions slick/src/sphinx/code/Connection.scala
Expand Up @@ -25,6 +25,12 @@ object Connection extends App {
val db = Database.forDataSource(dataSource: javax.sql.DataSource)
//#forDataSource
}
if (false){
val dataSource = null.asInstanceOf[slick.jdbc.DatabaseUrlDataSource]
//#forDatabaseURL
val db = Database.forDataSource(dataSource: slick.jdbc.DatabaseUrlDataSource)
//#forDatabaseURL
}
if(false) {
val jndiName = ""
//#forName
Expand Down
21 changes: 21 additions & 0 deletions slick/src/sphinx/database.rst
Expand Up @@ -38,6 +38,27 @@ until the JVM ends (``DB_CLOSE_DELAY=-1``, which is H2 specific).

.. index:: DataSource

Using a Database URL
--------------------

A Database URL, a platform independent URL in the
form ``vendor://user:password@host:port/db``,
is often provided by platforms such as Heroku.
You can use a Database URL in Typesafe Config as shown here:

.. includecode:: resources/application.conf#dburl

By default, the data source will use the value of the ``DATABASE_URL`` environment variable.
Thus you may omit the ``url`` property if the ``DATABASE_URL`` environment variable
is set. You may also define a custom environment variable with standard
Typesafe Config syntax, such as ``${?MYSQL_DATABASE_URL}``.

Or you may pass a :javaapi:`DatabaseUrlDataSource <slick/jdbc/DatabaseUrlDataSource>` object to
:api:`forDataSource <slick.jdbc.JdbcBackend$DatabaseFactoryDef@forDataSource(DataSource,AsyncExecutor,Boolean):DatabaseDef>`.

.. includecode:: code/Connection.scala#forDatabaseURL


Using a DataSource
------------------

Expand Down
10 changes: 10 additions & 0 deletions slick/src/sphinx/resources/application.conf
Expand Up @@ -29,3 +29,13 @@ tsql {
}
}
//#tsql

//#dburl
databaseUrl {
dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
properties = {
driver = "slick.driver.PostgresDriver$"
url = "postgres://user:pass@host/dbname"
}
}
//#dburl

0 comments on commit c44e9c8

Please sign in to comment.