ponyorm / pony

Pony Object Relational Mapper
Apache License 2.0
3.6k stars 243 forks source link

Feature request: support database connection URLs #391

Open fluffy-critter opened 5 years ago

fluffy-critter commented 5 years ago

Some application runtimes such as Heroku only provide your database connection in the form of a URL provided at deployment time. It would be nice if PonyORM supported these URLs directly.

An example URL is in the form:

postgres://username:password@hostname:port/db-name

urllib.parse.urlparse gets us most of the way there pretty easily, but it would be nice if PonyORM could apply domain-specific knowledge to do it end-to-end. In particular, handling the various fiddly cases of no port present and stripping out the initial / from the path to get db-name would be nice.

fluffy-critter commented 5 years ago

Oh, it looks like this could also be configured using:

db.connect(provider='postgres', dsn=os.environ['DATABASE_URL'])

It would still be swell if that could be simplified to just:

db.connect(url=os.environ['DATABASE_URL'])

though. :)

Melevir commented 3 years ago

While the feature is not realized, this snippet can help someone to configure Pony-powered app more easily: https://gist.github.com/Melevir/010881ef7c056ba118aca711d9a794c3

AstraLuma commented 2 years ago

Just hit this deploying an app to heroku.