Skip to content

Instantly share code, notes, and snippets.

@d1rtym0nk3y
Created April 1, 2013 18:08
Show Gist options
  • Save d1rtym0nk3y/5286580 to your computer and use it in GitHub Desktop.
Save d1rtym0nk3y/5286580 to your computer and use it in GitHub Desktop.
per application datasource parsed from environemnt variable with Railo 4.1
component {
sysenv = createObject("java", "java.lang.System").getenv();
dbUri = createobject("java", "java.net.URI").init(env("DATABASE_URL"));
this.datasources.default = {
class:'org.gjt.mm.mysql.Driver'
,connectionString:'jdbc:mysql://#dbUri.getHost()##dbUri.getPath()#?#dburi.getQuery()#'
,username: listfirst(dbUri.getUserInfo(), ":")
,password: listlast(dbUri.getUserInfo(), ":")
};
this.datasource="default";
private function env(required string name, string default) {
var result = variables.sysenv.get(name);
if(!isNull(result)) return result;
if(!isNull(arguments.default)) return arguments.default;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment