Permalink
Browse files

Add support for postgresql as an alternative to DSN scheme (#1723)

  • Loading branch information...
josegonzalez authored and cvogt committed Apr 25, 2017
1 parent 4b6f6f2 commit 066dc86d7387385c1a1457c52283fc42708708ce
@@ -57,6 +57,18 @@ databaseUrl {
}
}
// Test alternative dsn for postgres
altDatabaseUrl {
dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
properties = {
driver = "slick.test.jdbc.MockDriver"
url = "postgresql://user:pass@host/dbname"
properties = {
foo = bar
}
}
}
distrib1 {
profile = "slick.jdbc.H2Profile$"
db {
View
@@ -39,3 +39,13 @@ databaseUrl {
}
}
//#dburl
//#altdburl
altDatabaseUrl {
dataSourceClass = "slick.jdbc.DatabaseUrlDataSource"
properties = {
driver = "org.postgresql.Driver"
url = "postgresql://user:pass@host/dbname"
}
}
//#altdburl
@@ -47,6 +47,21 @@ class DataSourceTest {
} finally db.close
}
@Test def testAltDatabaseUrlDataSourceScheme: Unit = {
import slick.jdbc.H2Profile.api.actionBasedSQLInterpolation
MockDriver.reset
val db = JdbcBackend.Database.forConfig("altDatabaseUrl")
try {
assertEquals(Some(100), db.source.maxConnections)
try Await.result(db.run(sqlu"dummy"), Duration.Inf) catch { case ex: SQLException => }
val (url, info) = MockDriver.getLast.getOrElse(fail("No connection data recorded").asInstanceOf[Nothing])
assertEquals("jdbc:postgresql://host/dbname", url)
assertEquals("user", info.getProperty("user"))
assertEquals("pass", info.getProperty("password"))
assertEquals("bar", info.getProperty("foo"))
} finally db.close
}
@Test def testMaxConnections: Unit = {
MockDriver.reset
val db = JdbcBackend.Database.forConfig("databaseUrl", ConfigFactory.parseString(
@@ -6,7 +6,7 @@ package slick.jdbc
*/
class DatabaseUrlDataSource extends DriverDataSource(null) {
private val PostgresFullUrl = "^postgres://([a-zA-Z0-9_]+):([^@]+)@([^/]+)/([^\\s]+)$".r
private val PostgresFullUrl = "^(?:postgres|postgresql)://([a-zA-Z0-9_]+):([^@]+)@([^/]+)/([^\\s]+)$".r
private val MysqlFullUrl = "^mysql://([a-zA-Z0-9_]+):([^@]+)@([^/]+)/([^\\s]+)$".r
private val MysqlCustomProperties = ".*\\?(.*)".r

0 comments on commit 066dc86

Please sign in to comment.